From b1c761c2ecb76c18468bd508f69eb73d6dac4aa6 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Sun, 8 May 2016 00:00:48 +0800 Subject: [PATCH] fix: remove data handler when flushing command queue --- lib/cluster/index.js | 2 +- lib/redis.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/cluster/index.js b/lib/cluster/index.js index 926da182..959dc11c 100644 --- a/lib/cluster/index.js +++ b/lib/cluster/index.js @@ -337,7 +337,7 @@ Cluster.prototype.refreshSlotsCache = function (callback) { }; /** - * Flush offline queue and command queue with error. + * Flush offline queue with error. * * @param {Error} error - The error object to send to the commands * @private diff --git a/lib/redis.js b/lib/redis.js index 73626dd5..c1f62b2a 100644 --- a/lib/redis.js +++ b/lib/redis.js @@ -315,9 +315,6 @@ Redis.prototype.disconnect = function (reconnect) { if (this.status === 'wait') { eventHandler.closeHandler(this)(); } else { - if (this.stream) { - this.stream.removeAllListeners('data'); - } this.connector.disconnect(); } }; @@ -359,9 +356,14 @@ Redis.prototype.flushQueue = function (error) { item.command.reject(error); } - while (this.commandQueue.length > 0) { - item = this.commandQueue.shift(); - item.command.reject(error); + if (this.commandQueue.length > 0) { + if (this.stream) { + this.stream.removeAllListeners('data'); + } + while (this.commandQueue.length > 0) { + item = this.commandQueue.shift(); + item.command.reject(error); + } } };