Skip to content

Commit f7ce6b6

Browse files
committed
fix(worker): fix bzpopmin race condition
re #2619
1 parent 1f43976 commit f7ce6b6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/classes/worker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,14 @@ will never work with more accuracy than 1ms. */
715715
// We cannot trust that the blocking connection stays blocking forever
716716
// due to issues in Redis and IORedis, so we will reconnect if we
717717
// don't get a response in the expected time.
718-
timeout = setTimeout(async () => {
719-
bclient.disconnect(!this.closing);
718+
timeout = setTimeout(() => {
719+
// If the event-loop was stuck for more than 1s at the time of completion,
720+
// leading this setTimeout and the bzpopmin below to execute at the same time,
721+
// this function is going to run first. The next setTimeout is there to give
722+
// a bit of room to bzpopmin to resolve if it can.
723+
timeout = setTimeout(() => {
724+
bclient.disconnect(!this.closing);
725+
}, 0);
720726
}, blockTimeout * 1000 + 1000);
721727

722728
this.updateDelays(); // reset delays to avoid reusing same values in next iteration

0 commit comments

Comments
 (0)