fix(core): prevent TLA hang when has_tick_scheduled is set during async module evaluation#33278
Open
bartlomieju wants to merge 1 commit intomainfrom
Open
fix(core): prevent TLA hang when has_tick_scheduled is set during async module evaluation#33278bartlomieju wants to merge 1 commit intomainfrom
bartlomieju wants to merge 1 commit intomainfrom
Conversation
…nc module evaluation When CJS modules call `process.nextTick()` during module evaluation (setting `has_tick_scheduled = true`), the guarded microtask checkpoint in `mod_evaluate` was being skipped for async module graphs with TLA. This could leave V8's TLA resume microtasks unprocessed, causing the module evaluation promise to stay permanently Pending. Two fixes: 1. Always run the microtask checkpoint for async module graphs (`is_graph_async`), regardless of `has_tick_scheduled`. The nextTick ordering concern that motivates the guard only applies to user-visible promise callbacks, not to V8-internal TLA resolution machinery. 2. Replace the `unreachable!()` panic in the stalled TLA check with a graceful recovery: try one more microtask checkpoint before reporting, and if V8 reports no stalled TLAs but the evaluation is still pending, retry the event loop iteration instead of crashing. Fixes #32821 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
has_tick_scheduledis true during async module evaluation with TLAunreachable!()panic with graceful recovery when V8 reports no stalled TLA but evaluation is still pendingFixes #32821
Root cause
PR #32466 added a
has_tick_scheduled()guard to the microtask checkpoint inmod_evaluate(map.rs:1572). For async module graphs with TLA, this checkpoint is critical for draining V8's TLA resume microtasks. When CJS module initialization callsprocess.nextTick()(settinghas_tick_scheduled = true), the checkpoint is skipped, which can leave the evaluation promise permanently Pending in large module graphs.Changes
libs/core/modules/map.rs-- Primary fix:is_graph_async), regardless ofhas_tick_scheduledlibs/core/runtime/jsruntime.rs-- Safety net:unreachable!("Expected at least one stalled top-level await")with graceful handlinglibs/core/modules/tests.rs-- Regression test:test_tla_with_tick_scheduled_no_hang: verifies async module evaluation with TLA completes whenhas_tick_scheduledis set during evaluationTest plan
test_tla_with_tick_scheduled_no_hang-- async module graph with TLA + tick scheduledtest_lazy_loaded_esm_with_tla_no_panic-- still passestest_stalled_tla-- stalled TLA error reporting still works🤖 Generated with Claude Code