Skip to content

fix: catch unhandled rejection from dispatcher polling loop - #204

Merged
GiovaniGuizzo merged 1 commit into
sidequestjs:masterfrom
tsushanth:fix/dispatcher-listen-unhandled-rejection
Jul 21, 2026
Merged

fix: catch unhandled rejection from dispatcher polling loop#204
GiovaniGuizzo merged 1 commit into
sidequestjs:masterfrom
tsushanth:fix/dispatcher-listen-unhandled-rejection

Conversation

@tsushanth

Copy link
Copy Markdown
Contributor

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.

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
GiovaniGuizzo merged commit 1b1de09 into sidequestjs:master Jul 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants