Skip to content

Commit

Permalink
Free autopipelining callbacks when they stop getting used.
Browse files Browse the repository at this point in the history
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 65536 different arrays pointing to
callbacks that aren't needed.
  • Loading branch information
TysonAndre committed Nov 23, 2021
1 parent 2ee877e commit f2df554
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/autoPipelining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 2^16 slots
// in Redis.Cluster
pipeline[kCallbacks] = null;

// Perform the call
pipeline.exec(function (err, results) {
Expand Down

0 comments on commit f2df554

Please sign in to comment.