Repository navigation
[JSC] Module loader: replay the error of a failed fetch, and register nothing for a rejected fetch #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[JSC] Module loader: replay the error of a failed fetch, and register nothing for a rejected fetch #451
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //@ runDefault | ||
|
|
||
| // A module whose fetch was rejected while another module imported it keeps a | ||
| // FetchFailed registry entry, and the load of every later importer is settled | ||
| // from that entry by JSModuleLoader::hostLoadImportedModule(). It used to hand | ||
| // out JSModuleLoader::duplicateError()'s copy of the stored error, which keeps | ||
| // only its type and message. That copy exists for errors the host marked as | ||
| // fetch failures (moduleFetchFailureKind); an error the host rejected with | ||
| // itself, like the one this shell creates for a missing file, must be replayed | ||
| // unchanged, as the other replay sites (maybeDuplicateFetchError) already do. | ||
|
Comment on lines
+1
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| var abort = $vm.abort; | ||
|
|
||
| async function shouldReject(promise) { | ||
| try { | ||
| await promise; | ||
| } catch (e) { | ||
| return e; | ||
| } | ||
| throw new Error("did not reject"); | ||
| } | ||
|
|
||
| (async function () { | ||
| const first = await shouldReject(import("./resources/module-fetch-failed-replay/importer-a.js")); | ||
| if (!String(first).includes("does-not-exist")) | ||
| throw new Error("importer-a: unexpected error: " + first); | ||
| first.seenByFirstImporter = true; | ||
|
|
||
| const second = await shouldReject(import("./resources/module-fetch-failed-replay/importer-b.js")); | ||
| if (second.message !== first.message) | ||
| throw new Error("importer-b: unexpected error: " + second); | ||
| if (second !== first || !second.seenByFirstImporter) | ||
| throw new Error("importer-b: rejected with a copy of the stored fetch error instead of the error itself"); | ||
| }()).catch((error) => { | ||
| print(String(error)); | ||
| print(error.stack); | ||
| abort(); | ||
| }); | ||
|
Comment on lines
+23
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 nit (optional): maintainers get a green run from this test when a loader regression leaves the replayed import pending forever, so the test cannot catch that failure mode. The async IIFE at JSTests/stress/module-loader-fetch-failed-replays-host-error.js:23-38 only aborts when a promise settles wrongly; if import() of importer-b never settles, nothing runs, jsc drains and exits 0. Fix: make completion mandatory, e.g. set a done flag at the end of the IIFE and after drainMicrotasks() throw if it is unset, or use asyncTestStart(1)/asyncTestPassed() so the shell fails when the pass is never reported. The PR text itself names a load left pending forever as the loader's failure mode when FetchFailed entries are mishandled. Why this was flaggedThe test runs under //@ runDefault and ends with an async IIFE whose only failure signal is the .catch at JSTests/stress/module-loader-fetch-failed-replays-host-error.js:35-38, which prints and calls $vm.abort(). If a regression in JSModuleLoader::hostLoadImportedModule (Source/JavaScriptCore/runtime/JSModuleLoader.cpp:888-900) or in the FetchFailed entry handling leaves the second import() pending, the await at line 29 never resumes, no exception is thrown and abort() is never reached. The jsc shell exits 0 in that case: Source/JavaScriptCore/jsc.cpp:5090 only fails the run on an uncaught exception or when asyncTestExpectedPasses != asyncTestPasses, and this test registers no async pass. The shell provides asyncTestStart/asyncTestPassed (jsc.cpp:970-971) and many stress tests use a done flag checked after drainMicrotasks(); this test uses neither, so a never-settling load, which the PR description describes as a real failure mode of mishandled FetchFailed entries, reports as a pass. Verification: nit. If |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import "./does-not-exist.js"; | ||
| export const a = "a"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import "./does-not-exist.js"; | ||
| export const b = "b"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 nit (optional): maintainers sorting failures after an upstream sync cannot tell this new test is the fork's own, because it is not listed in JSTests/BUN-TEST-DIFFERENCES.md. The root CLAUDE.md names that file as the canonical list, and its "The fork's own tests" table (BUN-TEST-DIFFERENCES.md:195) is where fork-authored tests with upstream-style names such as stress/sort-scratch-double-pivot.js are recorded. Fix: add a row for stress/module-loader-fetch-failed-replays-host-error.js to that table saying what it holds the engine to (an unmarked fetch error is replayed as the same object by hostLoadImportedModule).
Why this was flagged
The diff adds JSTests/stress/module-loader-fetch-failed-replays-host-error.js:1 with an upstream-style name and does not touch JSTests/BUN-TEST-DIFFERENCES.md. CLAUDE.md:163 says that file lists every test the fork differs in and must be consulted when a test fails or after an upstream sync. Its section at JSTests/BUN-TEST-DIFFERENCES.md:195-204 lists fork-authored tests, including ones with upstream-style names such as stress/sort-scratch-double-pivot.js and stress/array-sort-inline-int32-double-comparator.js. On the base branch every fork-authored stress test is in that table; after merging, this one is the only one missing, so a maintainer sorting a failure of it or syncing upstream has no record that it is the fork's and what behaviour it pins. No guard prevents this; nothing checks the table against the tree.
Verification: The trigger is whenever someone sorts JSTests failures after an upstream sync using the canonical list, as the root CLAUDE.md directs.
git diff 4d45755..HEAD --stattouches exactly 5 files and not JSTests/BUN-TEST-DIFFERENCES.md. The new test has an upstream-style name and is absent from the "The fork's own tests" table at JSTests/BUN-TEST-DIFFERENCES.md:195-197, so the file the repository designates as the canonical list no longer lists every fork-authored test.