Skip to content

Commit b1c761c

Browse files
committed
fix: remove data handler when flushing command queue
1 parent 8a84482 commit b1c761c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

lib/cluster/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ Cluster.prototype.refreshSlotsCache = function (callback) {
337337
};
338338

339339
/**
340-
* Flush offline queue and command queue with error.
340+
* Flush offline queue with error.
341341
*
342342
* @param {Error} error - The error object to send to the commands
343343
* @private

lib/redis.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ Redis.prototype.disconnect = function (reconnect) {
315315
if (this.status === 'wait') {
316316
eventHandler.closeHandler(this)();
317317
} else {
318-
if (this.stream) {
319-
this.stream.removeAllListeners('data');
320-
}
321318
this.connector.disconnect();
322319
}
323320
};
@@ -359,9 +356,14 @@ Redis.prototype.flushQueue = function (error) {
359356
item.command.reject(error);
360357
}
361358

362-
while (this.commandQueue.length > 0) {
363-
item = this.commandQueue.shift();
364-
item.command.reject(error);
359+
if (this.commandQueue.length > 0) {
360+
if (this.stream) {
361+
this.stream.removeAllListeners('data');
362+
}
363+
while (this.commandQueue.length > 0) {
364+
item = this.commandQueue.shift();
365+
item.command.reject(error);
366+
}
365367
}
366368
};
367369

0 commit comments

Comments
 (0)