Repository navigation
fix(runtime): bound HTTP module fetches by the graph walk's deadline - #2171
Draft
edusperoni wants to merge 1 commit into
Draft
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This was referenced Dec 2, 2026
edusperoni
added a commit
that referenced
this pull request
Dec 2, 2026
…er URL (#2168) ### Description A module loaded over `http(s)` now resolves the specifiers it imports the way a browser does, for static `import` and `import()` alike, and it can no longer reach the app's filesystem implicitly. **Resolution follows the HTML module-specifier rules, through the WHATWG URL parser** (ada, the parser behind `new URL()`): - Only `/`, `./` and `../` prefixes are relative (`//host/x` is a `/` form). Anything else is an absolute URL if it parses as one, and a bare specifier otherwise. So `.x`, `.` and `..` are bare. - Dot segments and `\` resolve as in a browser, and the scheme is lowercased, so `HTTP://host/x` is an http URL. - The authority (userinfo, host, port) keeps the spelling the importer's URL, or the specifier, wrote. Dev tooling compares the module URLs the runtime reports against the origin it was configured with, verbatim. - The query is kept: `import('./x.js?v=1')` and `import('./x.js?v=2')` are two modules, as they are for a static import. **No implicit filesystem fallback from an HTTP module.** The shared resolver (graph walk, static resolve callback, `import()` callback) refuses these before anything is fetched or probed on disk: - a relative, root-relative or scheme-relative specifier that does not form an `http(s)` URL against the importer's URL; - an unmapped bare specifier, instead of falling back to `<app root>/<spec>`; - `~/x`. The errors name the specifier, the importer and what to use instead, e.g.: ``` Cannot resolve module specifier "lodash" imported from http://host/src/app.js: it is not in the import map (bare specifiers from an HTTP module must be mapped). ``` An unmapped specifier with another scheme (`data:`, `foo:bar`, `file:/x`) fails as `Cannot find module` without a disk lookup. Still allowed from an HTTP module: `ns:`/`node:` builtins, absolute `http(s)` URLs, an explicit `file:///…` URL, `blob:nativescript/…` URLs, and anything the import map maps. A mapped target is never refused, and a relative or root-relative target resolves against the importer's URL. `createRequire(<file path>)` stays the explicit way for an HTTP module to reach on-disk modules. **An import-map entry keyed by a module's own URL** never changes how that module's imports resolve. An HTTP module mapped to a file stays an HTTP importer, and a file module whose `file:///app/…` URL (or a prefix of it) is a map key stays a file importer. `docs/ns-builtin-modules.md` gains a "Specifier resolution" section for HTTP importers. #### Notes for review - **Import-map lookup of a query, from a file module.** On Android, a file module's static `import 'pkg?x'` and its `import('pkg?x')` both look `pkg?x` up in the map as written. The map is consulted before the query is dropped for the on-disk path, which is already how `main` works. A new spec pins it, and the docs state it. On iOS after NativeScript/ios#586, `import()` from a file module drops the query before the lookup, while a static import does not. The two platforms therefore differ for `import()` from a file module. This is one of the cross-platform decisions tracked in #2020; this PR doesn't change it. Note that #2020's description of the Android side predates this check. - File modules resolve exactly as before. ### Does your commit message include the wording below to reference a specific issue in this repo? No issue. ### Related Pull Requests Mirrors NativeScript/ios#586 (code, specs and the docs section). Part of a stack of six; each PR targets the branch below it: 1. #2168 `fix/http-importer-specifiers`: specifier resolution from HTTP importers (**this PR**, base `main`) 2. #2169 `refactor/module-url-parse`: one URL parse for every http(s) entry point 3. #2170 `perf/http-module-streaming-compile`: compile large HTTP modules off the JS thread 4. #2171 `fix/http-module-fetch-budget`: bound fetches by the graph walk's deadline 5. #2172 `perf/http-module-transport`: persistent connections, per-host-class caps, OkHttp transport 6. #2173 `feat/http-module-cache-controls`: HTTP module cache controls ### Does your pull request have [unit tests](https://github.com/NativeScript/NativeScript/blob/master/running-tests.md)? Yes. 21 new specs in `testEsmHttpLoader.js`, served by new `ModuleTestServer` routes and `esm/http-importer/`, `esm/self-mapped-*/` and `esm/query-map/` fixtures: - `./`, `../`, root- and scheme-relative `import()` load the URLs a browser computes, and the query is part of the module's identity. - Unmapped static and dynamic bare imports, `~/` and an other-scheme `import()` are refused. Same-named fixtures exist on disk, and an evaluation flag in each proves nothing was read. - Builtins, an explicit `file://` URL, import-map entries (any target form, including a relative one) and `blob:nativescript` URLs still load. - A module whose own URL is a map key (HTTP mapped to a file; a file module's exact and prefix entries) keeps its importer kind. - `.x`, `.` and `..` are refused as bare, statically and from `import()`. - Every spelling of one URL is one module, from `import()` and from a static import. Dot segments, `\` and an uppercase scheme normalize as the URL parser does. An importer served from a non-canonically spelled origin keeps that spelling in what it resolves. - A file module looks a static import's and an `import()`'s query up in the map as written. Full suite on the top of the stack (`./gradlew runtestsAndVerifyResults`): 2074 specs, 2068 passed, 0 failed, 6 skipped (the usual GC, native-module and environment skips), on an API 36 arm64 emulator with OkHttp in the test app, at `feat/http-module-cache-controls` 21f87a8. This stays a draft until the stack has been run against a real Vite dev session on Android, which has not happened yet. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * HTTP(S) modules now resolve relative and root-absolute imports against their URL, while import maps can rewrite specifiers and provide URL-relative targets. * Import resolution now handles built-in modules, file and blob URLs, and URL normalization consistently. * **Bug Fixes** * Unmapped bare and `~/` imports from HTTP modules are rejected with clearer errors instead of being treated as file paths. * File-based modules retain file-based resolution when their own URL is mapped. * **Documentation** * Clarified import-map behavior and documented HTTP module specifier resolution. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
A pumped graph walk waits at most kModuleEvaluateDeadlineSeconds for its fetches, but each async attempt carried a flat 15 s connect + 15 s read timeout and retried once unconditionally, so a stalled edge could keep fetching long after the wait had given up on it. - One timeout policy, ModuleFetchTimeoutMs(), now sets the connect and read timeouts of every attempt on both transports: 30 s in debug builds and 5 s in release builds, the same values as iOS (one of the cross-platform items tracked in #2020). - The pumped walk takes its deadline before starting and hands it to every fetch it issues (AsyncGraphLoad::fetchDeadline). An async attempt clamps both timeouts to the time remaining, the transport retry fires only while the budget still fits its 120 ms delay, and an attempt that would start past the deadline, including one queued behind the concurrency cap, fails with "HTTP import failed: <url> (module graph fetch deadline exceeded)" without issuing a request. - A dynamic import() of an HTTP root passes no deadline and stays unbounded; the synchronous fallback keeps its single retry. Mirrors NativeScript/ios#552, including its timeout values. Ports its slow-transform specs: a 7 s module, a 7 s re-export chain and a pumped require() through a local->HTTP boundary each resolve on one request per module.
edusperoni
force-pushed
the
fix/http-module-fetch-budget
branch
from
December 2, 2026 17:36
637b4a8 to
d31ee29
Compare
NathanWalker
approved these changes
Dec 2, 2026
This branch has not been deployed
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.
Description
A pumped graph walk waits at most
kModuleEvaluateDeadlineSecondsfor its fetches. Each async attempt, though, carried a flat 15 s connect + 15 s read timeout and retried once unconditionally. A stalled edge could therefore keep fetching long after the wait had given up on it.ModuleFetchTimeoutMs()sets the connect and read timeouts of every attempt: 30 s in debug builds and 5 s in release builds, the values iOS uses. That replaces 15 s / 15 s in both. Dev servers transform cold modules on demand. fix(runtime): give debug HTTP module fetches a 30s request budget ios#552 reports toolchain responses of 5–9 s, which is why debug gets the longer budget.AsyncGraphLoad::fetchDeadline). Each async attempt:HTTP import failed: <url> (module graph fetch deadline exceeded)without issuing a request when it would start past the deadline, including when it was queued behind the concurrency cap.import()of an HTTP root passes no deadline and stays unbounded, since nothing waits on it. The synchronous fallback keeps its single retry.The docs now give the timeout values and the deadline rules in place of the old per-attempt-bounds caveat.
Notes for review
security.allowRemoteModules. A slow remote origin that answered within 15 s now fails at 5 s, as it does on iOS.Does your commit message include the wording below to reference a specific issue in this repo?
No. It relates to #2020, a tracking issue that should stay open.
Related Pull Requests
Mirrors NativeScript/ios#552, including its timeout values and its slow-transform specs. The
/esm/slow/and/esm/request-stats.jsontest-server routes it relies on came in earlier in this stack.Part of a stack of six; each PR targets the branch below it:
fix/http-importer-specifiers: specifier resolution from HTTP importersrefactor/module-url-parse: one URL parse for every http(s) entry pointperf/http-module-streaming-compile: compile large HTTP modules off the JS threadfix/http-module-fetch-budget: bound fetches by the graph walk's deadline (this PR)perf/http-module-transport: persistent connections, per-host-class caps, OkHttp transportfeat/http-module-cache-controls: HTTP module cache controlsDoes your pull request have unit tests?
Yes. A new "fetch budget" group in
testEsmHttpLoader.jsuses/esm/request-stats.jsonto prove that each module was requested exactly once, with no retry and no synchronous-fallback round trip:require()through a local→HTTP boundary waits for a 7 s leaf.Full suite on the top of the stack (
./gradlew runtestsAndVerifyResults): 2074 specs, 2068 passed, 0 failed, 6 skipped (the usual GC, native-module and environment skips), on an API 36 arm64 emulator with OkHttp in the test app, atfeat/http-module-cache-controls21f87a8.This stays a draft until the stack has been run against a real Vite dev session on Android, which has not happened yet.