Skip to content

Pumping require() times out awaiting an import() started before it #2178

Backlog

Description

@edusperoni

What happens

While a synchronous load runs (any require() of an ES module), a module graph that an earlier import() is loading is held back: its modules are not evaluated and its promise stays pending until the require returns. A pumping require whose graph awaits that promise cannot settle, so it waits out deadlineSeconds (60 s by default) and then throws, or returns a pending namespace with onTimeout: "return-pending".

globalThis.p = import("./big.mjs");            // started before the require: held back
createPumpingRequire(__filename)("./b.mjs");   // b.mjs: await globalThis.p;

It applies to large local files and to HTTP modules. Plain require() refuses top-level await, and boot and Worker entries start before any other load, so only createPumpingRequire can reach it. An import() the graph starts itself is not held back.

iOS behaves the same. The hold through evaluation came from the review of NativeScript/ios#622 (commit 32d8e4e9), and #2177 ports it. The behaviour is documented under "Pumping requires" in docs/ns-builtin-modules.md. Reported by review on #2177.

Proposed change

Hold earlier loads back only while the require's graph is loading, and let them finish once it evaluates. The no-promise-jobs guarantee applies only to the loading wait: while a pumping require evaluates top-level await, it already runs promise jobs and nestable tasks from anywhere. So holding earlier loads back then only stops their modules' top-level code, and leaves the require open to the timeout above.

This needs a matching iOS change. The spec "does not evaluate an earlier import() while a pumping require() awaits" in testFileModuleLoad.js would then expect the opposite, and the docs note would go.

Activity

  1. edusperoni commented on Dec 5, 2026

    @edusperoni
    CollaboratorAuthor

    A related case to handle alongside this, from review on #2177: a require() of a module that an in-progress import() has already registered skips the graph walk.

    import("./root.mjs");   // small root registers right away; its large child loads in the background
    require("./root.mjs");  // finds the root registered (not yet instantiated) and skips the walk

    Linking then reaches the large child while its background load is still running, so the resolver compiles it on the JS thread instead of waiting for the background load. The result is correct: one compile, one instance, and the background load's finalize defers to the registered module. Only the off-thread speed-up is lost, and that load costs what it did before #2177. iOS does the same (ModuleInternal.mm, the reuse-registry branch skips RunModuleGraphLoadPumped).

    Possible fix on both platforms: run the graph walk for a registered root that is still kUninstantiated, keeping its identity, so the walk attaches to the in-flight job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions