Skip to content

Commit 7776183

Browse files
evantahlerclaude
andcommitted
Fix fire-and-forget async calls causing unhandled promise rejections during shutdown
Add .catch() handlers to all fire-and-forget async calls in Worker and Scheduler that were previously discarding Promise return values from timer callbacks. This prevents unhandled rejections when a shared Redis connection is closed during shutdown. Fixes #1260. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 30efdea commit 7776183

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/core/scheduler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export class Scheduler extends EventEmitter {
159159
private async pollAgainLater() {
160160
if (this.running === true) {
161161
this.timer = setTimeout(() => {
162-
this.poll();
162+
this.poll().catch((e) => this.emit("error", e));
163163
}, this.options.timeout);
164164
}
165165
}

src/core/worker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class Worker extends EventEmitter {
148148
this.started = true;
149149
this.emit("start", new Date());
150150
await this.init();
151-
this.poll();
151+
this.poll().catch((e) => this.emit("error", e));
152152
}
153153
}
154154

@@ -159,7 +159,9 @@ export class Worker extends EventEmitter {
159159
Math.round(new Date().getTime() / 1000),
160160
);
161161
await this.ping();
162-
this.pingTimer = setInterval(this.ping.bind(this), this.options.timeout);
162+
this.pingTimer = setInterval(() => {
163+
this.ping().catch((e) => this.emit("error", e));
164+
}, this.options.timeout);
163165
}
164166

165167
async end(): Promise<void> {
@@ -399,7 +401,7 @@ export class Worker extends EventEmitter {
399401
this.job = null;
400402

401403
if (this.options.looping) {
402-
this.poll();
404+
this.poll().catch((e) => this.emit("error", e));
403405
}
404406
}
405407

@@ -443,7 +445,7 @@ export class Worker extends EventEmitter {
443445
this.emit("pause");
444446
await new Promise((resolve) => {
445447
this.pollTimer = setTimeout(() => {
446-
this.poll();
448+
this.poll().catch((e) => this.emit("error", e));
447449
resolve(null);
448450
}, this.options.timeout);
449451
});

0 commit comments

Comments
 (0)