From b9ea7f4780948d4556548e6bf13e2c3271939d12 Mon Sep 17 00:00:00 2001 From: Manuel Astudillo Date: Thu, 16 Jun 2022 16:52:17 +0800 Subject: [PATCH] fix(worker): better disconnect when blocking connection --- lib/queue.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/queue.js b/lib/queue.js index 1c5ac9ab8..9e2e46ffe 100755 --- a/lib/queue.js +++ b/lib/queue.js @@ -570,7 +570,11 @@ async function redisClientDisconnect(client) { } Queue.prototype.disconnect = async function() { - await Promise.all(this.clients.map(redisClientDisconnect)); + await Promise.all( + this.clients.map(client => + client.blocked ? client.disconnect() : redisClientDisconnect(client) + ) + ); }; Queue.prototype.removeJobs = function(pattern) { @@ -1190,11 +1194,13 @@ Queue.prototype.getNextJob = async function() { // Waiting for new jobs to arrive // try { + this.bclient.blocked = true; const jobId = await this.bclient.brpoplpush( this.keys.wait, this.keys.active, this.settings.drainDelay ); + this.bclient.blocked = false; if (jobId) { return this.moveToActive(jobId);