feat: add allowWorkerIdleExit option to suppress idle-worker error events#133
Open
trafgals wants to merge 1 commit into
Open
feat: add allowWorkerIdleExit option to suppress idle-worker error events#133trafgals wants to merge 1 commit into
trafgals wants to merge 1 commit into
Conversation
…ents When a worker exits while it has no in-flight task, tinypool historically emits an `error` event on the public interface. This is useful for catching uncaught exceptions that fire after the task's synchronous return — but it also fires for workers that die from external causes (e.g. a child process crashing, a workerd subprocess segfaulting during teardown — see cloudflare/workerd#6763), which is a class of noise that the consuming pool often already has visibility into. Add an opt-in `allowWorkerIdleExit: boolean` option (default `false`). When `true`, the pool does not surface an `error` event for workers that exit while idle. Workers that exit mid-task still report the error to the in-flight task's callback, preserving the existing behavior for genuine task failures. A test pairs both modes against the same fixture so the regression for the default behavior is locked in alongside the new opt-in path.
AriPerkkio
requested changes
Jul 22, 2026
AriPerkkio
left a comment
Member
There was a problem hiding this comment.
Vitest no longer uses tinypool. Please try to reproduce the issue with vitest@4, and open a bug report on Vitest repository with a fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Tinypool currently emits an
errorevent on the public interface whenever a worker exits while it has no in-flight task. The intent is to surface post-task uncaught exceptions (e.g. an asyncsetTimeout(() => { throw ... }, 0)that lands afterpool.run()has returned), and that behavior is locked in bytest/uncaught-exception-from-handler.test.ts.The same code path also fires for workers that die from external causes that the consuming pool already has visibility into — most concretely, workerd subprocesses that segfault during teardown (see cloudflare/workerd#6763, also discussed in this comment thread on the upstream workerd issue tracker). When the workerd child dies after a vitest test file has reported its results,
cloudflare/vitest-pool-workersis unable to suppress the resultingWorker exited unexpectedlyevent, and the whole vitest run exits with code 1 even though every test body was already reported as passing.This PR adds an opt-in
allowWorkerIdleExit: booleanoption (defaultfalse) that lets consuming pools opt out of the publicerroremission for the idle-worker case. Workers that exit mid-task still surface the error to the in-flight task's callback, so genuine task failures continue to fail the affected task.How
Options.allowWorkerIdleExit?: boolean(defaultfalse)FilledOptions.allowWorkerIdleExit: boolean(the runtime-resolved value)kDefaultOptions.allowWorkerIdleExit = false(preserves current behavior)'error'handler is now a 3-branch conditional:errorevent)errorevent (unchanged)Tests
test/allow-worker-idle-exit.test.tsruns the same fixture twice — once with the option unset (asserting the existing error event) and once withallowWorkerIdleExit: true(asserting the error event is suppressed).test/uncaught-exception-from-handler.test.tscontinues to lock in the default behavior.Cross-references
Why not just patch vitest-pool-workers?
That pool does include a mitigation (PR #14793), but it has to live in their vendored copy of tinypool (
dist/worker/lib/tinypool.mjs) until/unless this option exists upstream. Surfacing it here lets the fix land once and apply to every pool that wants to suppress idle-worker noise.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com