Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove the lazy client error handler on close #1605

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/queue.js
Expand Up @@ -144,7 +144,9 @@ const Queue = function Queue(name, url, opts) {
this.clients = [];
const lazyClient = redisClientGetter(this, opts, (type, client) => {
// bubble up Redis error events
client.on('error', this.emit.bind(this, 'error'));
const handler = this.emit.bind(this, 'error');
client.on('error', handler);
this.once('close', () => client.removeListener('error', handler));

if (type === 'client') {
this._initializing = commands(client).then(
Expand Down Expand Up @@ -373,7 +375,7 @@ Queue.prototype._setupQueueEventListeners = function() {
const failedKey = this.keys.failed;
const drainedKey = this.keys.drained;

this.eclient.on('pmessage', (pattern, channel, message) => {
const pmessageHandler = (pattern, channel, message) => {
const keyAndToken = channel.split('@');
const key = keyAndToken[0];
const token = keyAndToken[1];
Expand All @@ -394,9 +396,9 @@ Queue.prototype._setupQueueEventListeners = function() {
this.emit('global:stalled', message);
break;
}
});
};

this.eclient.on('message', (channel, message) => {
const messageHandler = (channel, message) => {
const key = channel.split('@')[0];
switch (key) {
case progressKey: {
Expand Down Expand Up @@ -436,6 +438,14 @@ Queue.prototype._setupQueueEventListeners = function() {
this.emit('global:drained');
break;
}
};

this.eclient.on('pmessage', pmessageHandler);
this.eclient.on('message', messageHandler);

this.once('close', () => {
this.eclient.removeListener('pmessage', pmessageHandler);
this.eclient.removeListener('message', messageHandler);
});
};

Expand Down Expand Up @@ -561,6 +571,7 @@ Queue.prototype.close = function(doNotWaitJobs) {
.finally(() => {
this.childPool && this.childPool.clean();
this.closed = true;
this.emit('close');
}));
};

Expand Down