fix(realms): Make realm creation not hang with async ops running #99
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.
The way
JsRuntime::init_extension_js
initialized ESM extensions without a snapshot was by running the event loop and blocking the thread ntil there were no more tasks. This works fine for the main realm, because it is created before any user code can start any async ops. However, other realms may be created while async ops are running, which would make realm creation hang until those ops are resolved.Since extensions are not expected to use top-level await, there would be no need to run the entire event loop for modules to resolve; calling
JsRealm::evaluate_pending_module
would be enough. If the module is not resolved after calling that functions, then it or one of its dependencies has TLA, in which case we panic.Since a panic like "TLA is not allowed" would be hard to debug, especially on codebases with many modules, we use
ModuleMap::find_stalled_top_level_await
to find at least one of the TLA locations, and we display it in the panic message.