Skip to content

fix(workers): do not exit worker on unhandled rejections#5561

Merged
DavertMik merged 2 commits into
codeceptjs:4.xfrom
gololdf1sh:fix/worker-unhandled-rejection-no-exit
May 13, 2026
Merged

fix(workers): do not exit worker on unhandled rejections#5561
DavertMik merged 2 commits into
codeceptjs:4.xfrom
gololdf1sh:fix/worker-unhandled-rejection-no-exit

Conversation

@gololdf1sh
Copy link
Copy Markdown

@gololdf1sh gololdf1sh commented May 13, 2026

Problem

The unhandledRejection handler in runTests.js calls process.exit(1) for any rejection not matching expected / AssertionError. This kills the worker and silently drops every remaining test in its queue — they simply disappear from the report.

Common triggers (none related to test correctness):

  • Orphaned page.waitForResponse() that outlives a thrown error and rejects later
  • Auth plugin session-restore races between workers
  • video.saveAs after Playwright context close

Fix

Remove process.exit(1) — log the rejection, continue. uncaughtException handler is unchanged (genuinely unrecoverable). Restores 3.x behaviour.

gololdf1sh and others added 2 commits May 13, 2026 14:12
The worker process unhandledRejection handler currently calls
process.exit(1) for any rejection whose message is not "expected" /
"AssertionError". Exiting the worker silently drops every remaining
test in its queue — they do not appear in the failure summary, they
are missing entirely from the run report.

In real suites this triggers routinely from orphaned promises:

  - page.waitForResponse() created before an action that throws —
    the response promise outlives the throw and rejects with Timeout
    seconds/minutes later, after the scenario has already moved on
    (or finished).
  - Session-restore races in the auth plugin when multiple workers
    cold-cache simultaneously.
  - Playwright video.saveAs after a context close.

Measured on a 133-scenario suite, 4 workers, Node 22:

  Without this fix:   73 / 133 executed, 2 workers killed
                      → 60 tests silently lost from the report
  With this fix:     145 / 145 executed, 0 workers killed
                      → all rejections logged, failed tests stay in
                        the report, worker continues to next test

Restores 3.x behaviour (workers logged rejections and continued).

The uncaughtException handler keeps its current behaviour — that one
is genuinely unrecoverable.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DavertMik DavertMik merged commit f922ac8 into codeceptjs:4.x May 13, 2026
9 of 10 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.

2 participants