Skip to content

fix(core): import() waits for a pending TLA while another import settles - #37260

Open
phibar wants to merge 1 commit into
denoland:mainfrom
metatrom-ag:fix/dynamic-import-tla-settling-between
Open

phibar wants to merge 1 commit into
denoland:mainfrom
metatrom-ag:fix/dynamic-import-tla-settling-between

Conversation

@phibar

@phibar phibar commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #37259
Follow-up to #31670

A dynamic import() of a module that is still in its top-level await could resolve early, with the namespace's bindings uninitialized (Cannot access 'default' before initialization), when another dynamic import settled in between.

evaluate_dyn_imports took the whole list of pending dynamic module evaluations and only put the still pending ones back after resolving the settled ones. Resolving runs a microtask checkpoint, so code resumed by it could call import() for a module with a pending TLA while the list was empty. load_dynamic_import then found no pending evaluation and resolved right away instead of queueing a TLA waiter.

The still pending evaluations now go back into the list before any import is resolved.

Testing

  • New deno_core test test_dyn_import_pending_tla_while_other_import_settles; it fails without the fix.
  • cargo test -p deno_core --lib passes.
  • The reproduction from the issue prints {"second":"default is function","first":"default is function"} on a debug build with the fix.

AI disclosure

AI tools (Claude) were used to help write this change; it was reviewed by a human before submission.

`evaluate_dyn_imports` took the whole list of pending dynamic module
evaluations and only put the still pending ones back after resolving the
settled ones. Resolving runs a microtask checkpoint, so code resumed by it
could `import()` a module still in its top-level await while the list was
empty. `load_dynamic_import` then saw no pending evaluation and handed out
the namespace with its bindings uninitialized ("Cannot access 'default'
before initialization").

The still pending evaluations now go back before any import is resolved.

Follow-up to denoland#31670, which queued such imports as TLA waiters.

Fixes denoland#37259
@phibar

phibar commented Dec 2, 2026

Copy link
Copy Markdown
Author

Note for reviewers: there are two ways to fix #37259, and I opened both so you can choose.

The two are independent and can both land; they only conflict textually at the end of libs/core/modules/tests.rs, where each appends its test. If you prefer a single change, #37262 alone covers both issues, and I'm happy to close this one or rebase whichever lands second.

@CLAassistant

CLAassistant commented Dec 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import() of a module still in its top-level await resolves early when another module's top-level await settles in between

2 participants