fix: catch unhandled rejection from dispatcher polling loop - #204
Merged
GiovaniGuizzo merged 1 commit intoJul 21, 2026
Merged
Conversation
start() called void this.listen() with no .catch(). listen() awaits
DB calls without a try/catch, so a transient connection error causes
the loop to exit and the rejection to surface as an unhandled rejection.
In Node >= 15 this crashes the process; in older Node it silently kills
the polling loop and jobs pile up in waiting state with no recovery.
The same file already handles this correctly for job execution:
void this.executorManager.execute(queue, job).catch((error: unknown) => {
logger("Dispatcher").error(`Unexpected error executing job ${job.id}:`, error);
});
Apply the same pattern to start().
GiovaniGuizzo
approved these changes
Jul 20, 2026
merencia
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`Dispatcher.start()` calls `void this.listen()` without a `.catch()`. The `listen()` loop awaits DB calls that can throw on a transient connection error. When that happens, the rejected promise surfaces as an unhandled rejection — crashing the process in Node ≥ 15, or silently killing the polling loop in older Node (jobs stall in waiting state with no recovery).
The same file already handles this correctly for job execution:
```ts
void this.executorManager.execute(queue, job).catch((error: unknown) => {
logger("Dispatcher").error(`Unexpected error executing job ${job.id}:`, error);
});
```
Fix
Apply the same pattern to `start()`:
```ts
void this.listen().catch((error: unknown) => {
logger("Dispatcher").error("Dispatcher polling loop crashed unexpectedly:", error);
});
```
A follow-up could wrap the `while` body in try/catch to recover from transient errors without restarting the whole loop, but this `.catch()` prevents the process crash in the meantime.