Repository navigation
Conversation
…) alive JSModuleLoader::attachErrorInfo() stored the module record of the failing Evaluate() or Link() on the error, as a private property. getErrorInfo() read it back into ModuleFailure::m_source, which nothing uses: ModuleFailure::isEvaluationError() looks at the key, the type and the kind. An error that a program keeps therefore kept the record alive, and with it every module of the graph that the record reaches, evaluated or not. For the records of Bun's node:vm, which are in no registry, that was the only thing that kept them alive. The record is no longer stored. The key, the type and the kind are.
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs; because the fix relies on nothing outside this tree (Bun's embedder code) reading the record private name back, a human look would still be worthwhile.
What was reviewed:
- Traced every in-tree reader of the record: getErrorInfo() at JSModuleLoader.cpp:203 is the only one, and both of its callers (JSMicrotask.cpp:1248, :1439) only call isEvaluationError(), which uses key/type/kind.
- Checked ModuleFailure::operator bool() (line 196): no in-tree caller uses it, and every attachErrorInfo call site that passed a record also passes a non-null key, so it would stay true anyway.
- duplicateError/duplicateTypeError still copy the record name (lines 101, 145) — a harmless no-op on Bun builds since it is never written.
- The #else branch preserves upstream behavior, matching the USE(BUN_JSC_ADDITIONS) convention.
Extended reasoning...
The diff is a nine-line change to one function, JSModuleLoader::attachErrorInfo in Source/JavaScriptCore/runtime/JSModuleLoader.cpp, that under USE(BUN_JSC_ADDITIONS) stops storing the AbstractModuleRecord on the error object as a private property, with the upstream putDirect kept in the #else branch. It touches no security-sensitive surface; it is a memory-retention fix for module evaluation errors. Within this tree the change is correct: the only reader of the private name feeds ModuleFailure, and the sole consumers use isEvaluationError(), which never looks at m_source. I did not approve because the correctness also depends on Bun's out-of-tree embedder not reading that private name (the PR author reports Bun's tests pass but that cannot be checked here), no JSTests regression test accompanies the change, and .github/CODEOWNERS assigns Source/JavaScriptCore to jsc-reviewers.
|
Preview build of 7964380: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
ChangesModule loader error metadata
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
Problem
Evaluate()that failed, and with it every module of that graph. In Bun, anErrorthat a program keeps from a failednode:vmgraph of 23 modules holds 1,120 KB of heap. Without the record it holds 18 KB. An error of the host also keeps the wholevmcontext.JSModuleLoader::attachErrorInfo(JSModuleLoader.cpp:217) stores the record on the error as a private property.getErrorInfo()reads it back intoModuleFailure::m_source, which nothing uses.Fix
attachErrorInfodoes not store the record. The key, the type and the kind stay.ModuleFailure::isEvaluationError(), the only consumer, reads the key, the type and the kind.vm-module-graph-evaluation*.test.ts,dynamic-import-evaluation-error-gc.test.tsanddynamic-import-tla-cycle.test.tspass. NoJSTestsfile: the registry of thejscshell keeps every record alive.Background
Evaluate()of a cyclic module record stamps an error that its walk throws (CyclicModuleRecord.cpp:619). The loader reads the stamp later to tell an evaluation error from a fetch error or a link error.node:vmare in no registry. When the program drops its modules, nothing else keeps the records alive.Downsides
getErrorInfo()(JSMicrotask.cpp:1248and:1439) andModuleFailure::operator bool(), which stays true through the key and the kind.Notes
vm.SyntheticModulewhose callback never runs. The program keeps the 100 errors. With the record on the error: 109 MB of heap, and 100 of the 100 callbacks stay alive. Without it: 2 MB, and 0 of 100.vmcontexts, each with a graph whoseevaluateCallbackthrows anErrorof the main realm, and the program keeps the errors: 20 of 20 contexts stay alive with the record, 0 of 20 without it.node:vmtest for this when it takes this change.