Reap crashed Turbopack plugin workers instead of hanging forever
When a worker-thread plugin runtime dies unexpectedly (uncaught exception,
process.exit, OOM), nothing told the Rust worker pool about it: the dead
Worker stayed in loaderWorkers, the operation waiting for its response
hung forever, and every later evaluation could be handed the dead worker,
wedging the dev server's compilation permanently. This is the crash-time
sibling of #96592, which covered evaluation and IPC errors reported over
the channel.
JavaScript now attaches 'error'/'exit' listeners to pooled workers and
reports any death while the worker is still registered (intentional
terminations remove the worker from the map first, so they are never
reported; the thread id is captured at creation since it resets to -1 by
the time 'exit' fires). On the Rust side, a dead-worker set records
reaped ids and handle_worker_death classifies the death:
- busy: closes the in-flight task's channel (via a watch channel, which
cannot lose the wakeup), so its pending recv fails and surfaces through
the existing subprocess-crash path in pull_operation - synthesized
issue, disallow_reuse, fresh worker on the next evaluation;
- idle: removed from the idle list and pool statistics;
- created but unassigned (in transit to an acquirer or routed to a
waiter): total worker count decremented;
- boot failure: the pending creation for the same pool is failed (so
create_worker errors instead of waiting forever) and the booting
statistics are balanced - no phantom workers after a boot crash.
Every acquisition and return path checks the dead set so a reaped id is
never handed out again: acquire_worker retries after dead candidates
(idle pop, waiter handoff, fresh boot), and WorkerOperation's drop skips
returning a worker that died while checked out.
Verified end to end with turbopackPluginRuntimeStrategy: 'workerThreads':
- before: a loader calling process.exit(1) hangs the request forever and
wedges all later compilations;
- after: the request fails in ~1s with "Node.js subprocess crashed while
evaluating loaders", and the next request is served by a fresh worker
in ~50ms. A worker that dies between tasks (idle) is reaped the same
way.
The new development test covers the crash path: baseline (stock binary)
fails by hanging; candidate fails the evaluation and recovers. The #96592
error-cleanup test still passes. Autoreview panel findings addressed:
watch-channel close, dead-set validation on all handoff paths,
options-tagged pending creations, clean-exit reaping.
Validation: pnpm build-all (TS + native), cargo fmt --check, cargo clippy
-p turbopack-node --all-targets -D warnings, cargo test -p turbopack-node
--lib, candidate integration test pass, exact baseline binary fails by
hanging.
Co-Authored-By:
Marcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
Showing
This diff is collapsed.
This diff is collapsed.
Please
register
or
sign in
to comment