Report unavailable Node builtins as module errors instead of crashing workerd#14619
Open
momomuchu wants to merge 2 commits into
Open
Report unavailable Node builtins as module errors instead of crashing workerd#14619momomuchu wants to merge 2 commits into
momomuchu wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 94e4154 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
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.
Fixes #14590.
What
In
@cloudflare/vitest-pool-workers, if a Worker under test statically imports (or requires) anode:*builtin that is not actually available at the Worker's resolved compatibility date and flags, workerd crashes with*** Received signal #11: Segmentation faultat pool startup, before any test runs, reporting onlyWorker exited unexpectedlywith no mention of the offending module. The same Worker underwrangler devfails cleanly withNo such module "node:child_process".Why
The module fallback service maps any id in
workerdBuiltinModulesto a/node:*redirect. That set is generated at the latest compatibility date, so it includes builtins the running workerd does not serve at the Worker's resolved (earlier) date, or without the requiredenable_nodejs_*flag. Redirecting one of those drives workerd into a path that segfaults, whereas reporting the module as not found lets workerd resolve at the root and produce a cleanNo such moduleerror. The redirect was also kept unconditionally forrequire(), so that path crashed even after the import path was guarded.How
Compute, per resolved
(compatibilityDate, compatibilityFlags), whether each compatibility-gated Node builtin is actually available, applied to both the import and require fallback paths. Availability uses the(enableFlag, disableFlag, defaultOnDate)rules from@cloudflare/unenv-preset(packages/unenv-preset/src/preset.ts): a builtin is available when its disable flag is absent and either its enable flag is present or the resolved date is on or after its default-on date.Only native-only gated builtins are gated (those whose preset override has no polyfill, hybrid, or injected fallback, so a redirect would crash):
os, http2, punycode, cluster, trace_events, domain, wasi, inspector(andinspector/promises),sqlite, dgram, _stream_wrap, repl, child_process, worker_threads, readline(andreadline/promises), and_http_server(behind the separate http-server sub-gate at 2025-09-01). Builtins that have a polyfill or are injected or force-enabled by the pool (console,vm,process,perf_hooks,http,https,fs,tty,v8) stay available and resolve unchanged.To keep the gated table from silently drifting out of sync with
preset.ts, a drift-guard test (test/builtin-module-availability.test.ts) pins every entry to the livegetCloudflarePreset(...)at its boundary dates and asserts, both ways, that the map covers exactly the native-only gated set. A future preset change to a flag name or date fails CI instead of quietly reintroducing the crash.vitest-pool-workersmodule-resolution behavior (a crash becomes a clear error). There is no user-facing API or documented-behavior change.