fix(run): kill a worker that blocks its event loop past the test timeout
A test body that blocks the worker's event loop (while (true) {}) never timed out: the test timeout is a timer inside the worker, which never fires, and the runner had no deadline of its own. The run hung until someone killed the worker process. Ctrl-C did not end it either.
- The worker sends
attempt-deadline(test timeout andcleanupTimeout) when an attempt's timeout starts, andattempt-endwhen the attempt ends (packages/e2e/src/run/execute.ts,worker/session.ts). - From the deadline on, the scheduler sends
pingonce percleanupTimeout(at least 5 s). The worker answerspongright away, outside its unit queue. A worker that misses one is SIGKILLed through the existing crash path (SchedulerWorker.watchinpackages/e2e/src/run/scheduler.ts). A worker still tearing down a timed-out attempt keeps answering and is not killed. - The hung test is reported
timed-outwithTEST_TIMEOUT(exit 1, noWORKER_EXITrun error). The file's tests it never reached are put back in the queue and run on a new worker, as they would after a normal timeout. If the target failed meanwhile (workers could not boot), they are skipped instead of left in a queue nothing reads. worker/entry.tssendnow passes every message to the channel right away. It used to wait for the previous message's write callback, so anattempt-deadlinesent just before a blocking body (for example a serial member right after the previous one) never left the process.- No watchdog for a worker with a debugger attached when the attempt starts (editor auto-attach,
NODE_OPTIONS=--inspect=0), so a paused breakpoint is not killed. In-process runs (inline config, in-memory tests) share the runner's event loop, so nothing can enforce the timeout there. The docs say so. - Builds on #837: the kill goes through its crash bookkeeping (
synthesizeCrashResults). The attempts finished before the hung one stand, and the hung one is appended at its index astimed-out/TEST_TIMEOUT, with the id and start the worker sent inattempt-deadline. It is not retried. A hung serial member settles throughSerialGroupProgress.crashedwith statustimed-out: earlier members keep their records, the ones after it skip. - The
sendchange inworker/entry.tswas the same in #837, so there is one implementation now.
sequenceDiagram
participant S as scheduler
participant W as worker
W->>S: attempt-deadline (timeout, cleanupTimeout)
Note over W: body blocks the event loop
S->>W: ping (at timeout)
Note over S: no pong within cleanupTimeout (>= 5 s)
S->>W: SIGKILL
S->>S: report timed-out, requeue unreached tests
Verified
Ran it locally: yes
- testbed, a scratch
tests/zz-busy.e2e.ts(a 2 s timeout test that runsapp.open()and thenwhile (true) {}, followed by a passing test),node node_modules/e2e/dist/cli/bin.js run tests/zz-busy.e2e.ts --workers 1with the default 30 scleanupTimeout.
| main | this branch |
|---|---|
Hung. timeout 120 sent SIGTERM and the run still did not end. It finished only after I kill -9'd the spinning worker at 212 s, with both tests skipped and a WORKER_EXIT error | Ended in 34 s, exit 1 |
main:
ERROR infrastructure error WORKER_EXIT
worker for target "web" exited unexpectedly (code null, signal SIGKILL) during file::web::tests/zz-busy.e2e.ts
Test Files 0 passed | 1 skipped (1)
Tests 0 passed | 2 skipped (2)
Duration 211.96s (3m 32s, startup 86ms)
this branch:
❯ |web| tests/zz-busy.e2e.ts (2 tests | 1 failed) 32.13s
× blocks the event loop (timed-out) 32.01s
✓ runs after it 123ms
FAIL |web| tests/zz-busy.e2e.ts > blocks the event loop
TEST_TIMEOUT: test ran past its 2000 ms timeout and its worker stopped responding, so the worker was killed
Tests 1 failed | 1 passed (2)
Duration 32.82s
(The branch output above was captured before the message wording changed. The behavior is the same.)
After the rebase on #837, same testbed setup with retries: 1, attempt 0 throws, attempt 1 while (true) {}: exit 1 in 34 s, report.json attempts [[0, failed, ERROR "first attempt fails"], [1, timed-out, TEST_TIMEOUT]], the next test passed.
Tests: new integration tests in parallel-workers.test.ts cover a body that blocks immediately, one that blocks after a step, a serial member, and a slow teardown that answers pings and is left alone. The first one hangs on main, and the slow-teardown test fails if the worker's ping handler is removed. Scheduler unit tests cover the kill and requeue, and pings that are answered. Added for the #837 integration: the retry case above (integration and unit) and a target that fails while a worker hangs (unit, hung forever before the fix). Mutation-checked: dropping the kept attempts or the serial timed-out status fails them.