From 618c6d4b3c97e42e219ae2f399bb9d964b28abab Mon Sep 17 00:00:00 2001 From: Eli Skeggs Date: Thu, 16 Apr 2020 13:57:47 -0700 Subject: [PATCH] fix(queue): remove error event listener on close The error event listener is useful for catching errors from redis clients that aren't managed by the consumer of the library, but might cause problems for re-used connections. --- lib/queue.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/queue.js b/lib/queue.js index 39e4e3ff..b899629e 100644 --- a/lib/queue.js +++ b/lib/queue.js @@ -75,6 +75,8 @@ class Queue extends Emitter { return redis .createClient(this.settings.redis, createNew) .then((client) => { + // This event gets cleaned up and removed in Queue#close for the + // primary client if quitCommandClient is disabled. client.on('error', this._emitError); return (this[clientName] = client); }); @@ -222,8 +224,12 @@ class Queue extends Emitter { this._isClosed = true; const clients = []; - if (this.settings.quitCommandClient && this.client) { - clients.push(this.client); + if (this.client) { + if (this.settings.quitCommandClient) { + clients.push(this.client); + } else { + this.client.removeListener('error', this._emitError); + } } if (this.eclient) { clients.push(this.eclient);