Repository navigation
fix(vm): fall back to compiling from source when a module's code cache is rejected - #11031
sheremet-va merged 3 commits into
Conversation
β¦e is rejected The vm ESM executor reuses V8 code cache for externalized ES modules across contexts (vitest-dev#10744). Unlike vm.Script, which only sets cachedDataRejected, a SourceTextModule throws ERR_VM_MODULE_CACHED_DATA_REJECTED when V8 rejects the cache - and V8 rejects it for the rest of a worker's life once any test changes V8 flags at runtime (v8.setFlagsFromString('--expose-gc') is a common way to get gc() in a test), because the flag hash the cache is checked against changes. Every later file on that worker then failed to load its ESM externals. Catch the rejection, drop the cache entry and compile from source.
|
Hello @MarshallOfSound. Your PR has been labeled To keep your PR open, please follow these steps:
Please, do not generate or format the response with AI. If you do not speak English, reply in your native language or use translation software like Google Translate or Deepl. If the response is generated, the PR will be closed automatically. These measures help us reduce maintenance burden and keep the team's work efficient. See our AI contributions policy for more context. |
|
Sorry about #11030 got hit with the PR limit and the github UI led me to "make it a draft anyway" which then reset my PR body π Apparently the auotmated check still fires for definitely hand crafted PRs in the github UI though? Once again, reviewed this one carefully, purely a behavior fix |
|
There are a bunch of ways to set v8 flags unfortunately, We could probably make it better for some of them but node loves adding ways to set these flags so it'll be a game of whackamole. Happy to play whackamole but the generic "if one of these slips through we shouldn't hard error" fix I think still applies? So maybe we land this and I send another PR after with a more optimized happy path for usage of |
|
Are you setting them outside the worker? I donβt think NODE_OPTIONS take affect after the worker spawns, and βv8-options you need to pass down to the worker from the outside (I assume via execArgv) |
|
Not outside, it's inside the worker, at runtime. The case we hit is a test calling We can patch the
And once the process's flag hash changes, every later |
I don't think this would matter? Externalized code runs via vm mechanism from this PR. Setup/environment runs before any of the cache is populated, and it doesn't have access to VM cache.
This could break it, I agree. I think the patch you propose should go anyway (what's in this PR). But patching |
β¦de:v8
The vm context now gets a node:v8 whose setFlagsFromString empties the ESM
code cache right after the real call, so in the common case (a test or helper
calling v8.setFlagsFromString('--expose-gc')) no later module is even offered
stale cached data. The fallback in createSourceTextModule stays for flag
changes that do not go through that module (native addons, the worker realm's
own binding); the e2e test covers both paths.
|
@sheremet-va Done + tested π |
|
LGMT! Thanks for testing the rc! |
Note
This PR was made with assistance from Claude in both identifying the issue and generating the patch
Description
The vm ESM executor's V8 code cache for externalized ES modules (#10744) broke every later file on a worker once any test changed V8 flags at runtime (e.g. v8.setFlagsFromString('--expose-gc')), because SourceTextModule throws ERR_VM_MODULE_CACHED_DATA_REJECTED on a flag-hash mismatch rather than just setting cachedDataRejected like vm.Script... Now we catch it and compile from source
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.