fix(runtime): warn on unsupported web Worker options and fix recv panic#33310
Merged
Conversation
Emit a console warning when node-specific options like `env` or `workerData` are passed to the web `Worker()` constructor, directing users to `node:worker_threads` instead. These options are silently ignored by web Workers, which can lead to subtle bugs like infinite worker recursion (fixes #31058). Also replace `handle_receiver.recv().unwrap()` in `op_create_worker` with a proper error return, so a worker thread dying before initialization produces a JS error instead of a process panic. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
env,workerData) are passed to the webWorker()constructor, directing users tonode:worker_threadsinstead. These options are silently ignored by web Workers, which can lead to subtle bugs like infinite worker recursion.handle_receiver.recv().unwrap()inop_create_workerwith a proper error return, so a worker thread dying before initialization produces a JS error instead of a process panic.Fixes #31058
Root cause
The issue reporter passed
{ env: { IS_WORKER: "true" } }tonew Worker()(web worker). The web Worker constructor silently ignoresenv(it's a node:worker_threads option). The spawned worker couldn't detect it was a worker (process.env.IS_WORKERwas never set), so it entered the main code path and recursively spawned more workers exponentially. This exhausted OS resources until Rust's thread initialization panicked trying to allocate a signal stack.Test plan
tests/specs/worker/worker_unsupported_options/— verifies warning for bothenvandworkerDatanode:worker_threadsspec tests passcargo check -p deno_runtimeclean🤖 Generated with Claude Code