Skip to content

fix(codeceptjs): prevent IPC race and hang in test utils on Windows/Node 26#1504

Merged
todti merged 4 commits into
mainfrom
worktree-fix+codeceptjs-pageobject-sync-throw-windows
Jun 1, 2026
Merged

fix(codeceptjs): prevent IPC race and hang in test utils on Windows/Node 26#1504
todti merged 4 commits into
mainfrom
worktree-fix+codeceptjs-pageobject-sync-throw-windows

Conversation

@todti

@todti todti commented May 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Test midweight (26, windows-latest) was flakily failing on pageObject.test.ts > should report broken steps in page objects for raw errors. Two failure modes were observed:

  1. Hang / timeout — the exit event on the forked CodeceptJS process never fired, so runCodeceptJsInlineTest never resolved. Vitest killed the test after 5 000 ms.
  2. Zero results — the process exited, but messageReader.results.tests was empty. The exit event fired before all pending IPC messages (sent via process.send() in the child) were dispatched to the parent's message listener.

Root cause: on Windows + Node 26, a synchronous throw inside a page-object step helper triggers an unhandled-exception path in CodeceptJS that either stalls the process or causes it to exit before the IPC channel is fully drained. The same code path works fine on Linux.

Fix

Two targeted changes to test/utils.ts (no production code touched):

Change Failure mode addressed
setTimeout(kill, 30_000) — send SIGTERM if the child does not exit on its own hang / timeout
await new Promise(r => setImmediate(r)) before reading results — yield to the event loop once after exit zero results (IPC drain race)

Testing

All 6 tests in pageObject.test.ts pass locally. The hang/race is Windows-specific and will be confirmed by CI.

todti added 2 commits May 30, 2026 13:01
…ode 26

On Windows with Node 26, a synchronous throw inside a page-object step
helper caused the forked CodeceptJS process to either:
  - hang indefinitely (the 'exit' event never fired), making the vitest
    test time out at 5 000 ms; or
  - exit before all pending IPC messages were dispatched to the parent,
    resulting in 0 collected test results.

Two targeted fixes in test/utils.ts:
  1. Kill timeout (30 s): sends SIGTERM to the child process if it does
     not exit on its own, preventing the hang.
  2. setImmediate drain: yields to the event loop once after 'exit'
     before reading messageReader.results, letting any IPC message
     callbacks that are already queued run first.
@todti todti added theme:build type:bug Something isn't working type:improvement Improvement or request labels May 30, 2026
@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown

Allure Report Summary

Name Duration Stats New Flaky Retry Report
Allure JS – Pull request #1504 2h 7m Passed tests 4667   Failed tests 2 0 0 0 View

@todti
todti merged commit d23ec05 into main Jun 1, 2026
38 of 40 checks passed
@todti
todti deleted the worktree-fix+codeceptjs-pageobject-sync-throw-windows branch June 1, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:codeceptjs type:bug Something isn't working type:improvement Improvement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants