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(worker): make sure clearTimeout is always called after bzpopmin #2553

Merged
merged 1 commit into from
May 1, 2024
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
6 changes: 4 additions & 2 deletions src/classes/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ will never work with more accuracy than 1ms. */
return Infinity;
}

let timeout: NodeJS.Timeout;
try {
if (!this.closing) {
let blockTimeout = this.getBlockTimeout(blockUntil);
Expand All @@ -629,7 +630,7 @@ will never work with more accuracy than 1ms. */
// We cannot trust that the blocking connection stays blocking forever
// due to issues in Redis and IORedis, so we will reconnect if we
// don't get a response in the expected time.
const timeout = setTimeout(async () => {
timeout = setTimeout(async () => {
await this.blockingConnection.disconnect();
await this.blockingConnection.reconnect();
}, blockTimeout * 1000 + 1000);
Expand All @@ -639,7 +640,6 @@ will never work with more accuracy than 1ms. */
// Markers should only be used for un-blocking, so we will handle them in this
// function only.
const result = await bclient.bzpopmin(this.keys.marker, blockTimeout);
clearTimeout(timeout);

if (result) {
const [_key, member, score] = result;
Expand All @@ -659,6 +659,8 @@ will never work with more accuracy than 1ms. */
if (!this.closing) {
await this.delay();
}
} finally {
clearTimeout(timeout);
}
return Infinity;
}
Expand Down