From fb100ffff1c3cf1cfa956d7f9333f750b78c14cd Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Tue, 23 Nov 2021 10:22:55 -0500 Subject: [PATCH] Free autopipelining callbacks when they stop getting used. Set kCallbacks field to null instead of the empty array because nothing should append to it until a new pipeline starts. If anything did, that is a bug. With Redis.Cluster, there could be 16384 different arrays pointing to callbacks that aren't needed. --- lib/autoPipelining.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/autoPipelining.ts b/lib/autoPipelining.ts index 40b456334..0251dd147 100644 --- a/lib/autoPipelining.ts +++ b/lib/autoPipelining.ts @@ -45,6 +45,10 @@ function executeAutoPipeline(client, slotKey: string) { client._autoPipelines.delete(slotKey); const callbacks = pipeline[kCallbacks]; + // Stop keeping a reference to callbacks immediately after the callbacks stop being used. + // This allows the GC to reclaim objects referenced by callbacks, especially with 16384 slots + // in Redis.Cluster + pipeline[kCallbacks] = null; // Perform the call pipeline.exec(function (err, results) {