Fix for-await-of inside async generators permanently suspending#2353
Merged
Conversation
…promise resolves Co-authored-by: lahma <171892+lahma@users.noreply.github.com> Agent-Logs-Url: https://github.com/sebastienros/jint/sessions/0cabd5d1-d093-43e6-9b1f-5369934f0067
Co-authored-by: lahma <171892+lahma@users.noreply.github.com> Agent-Logs-Url: https://github.com/sebastienros/jint/sessions/0cabd5d1-d093-43e6-9b1f-5369934f0067
Copilot
AI
changed the title
[WIP] Fix async test failures in Jint.Repl
Fix for-await-of inside async generators permanently suspending
Mar 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a deadlock where for await...of inside async function* would suspend the generator body and never resume, leaving the outer .next() promise permanently pending.
Changes:
- Add an async-generator-specific continuation path (
AsyncGeneratorContinueForAwait) to resume the current dequeued request after afor-await-ofsuspension. - Track
for-await-ofiterator.next()rejections viaForAwaitSuspendData.RejectedValueand rethrow on resume within async generators. - Add regression tests covering
for awaitinside async generators (including destructuring and multiple suspensions).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Jint/Runtime/SuspendData.cs | Extends ForAwaitSuspendData with RejectedValue to propagate iterator .next() promise rejections on resume. |
| Jint/Runtime/Interpreter/Statements/JintForInForOfStatement.cs | Switches async-generator for-await-of resumption to AsyncGeneratorContinueForAwait, queues resumption via event loop, and throws stored rejection on resume. |
| Jint/Native/AsyncGenerator/AsyncGeneratorInstance.cs | Introduces AsyncGeneratorContinueForAwait to resume execution without relying on the request queue. |
| Jint.Tests/Runtime/AsyncTests.cs | Adds regression tests for for await inside async function* bodies (including destructuring and repeated suspensions). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: lahma <171892+lahma@users.noreply.github.com> Agent-Logs-Url: https://github.com/sebastienros/jint/sessions/eeb65211-1fbb-4ed4-a2cc-a73dfde43d01
lahma
approved these changes
Mar 23, 2026
lahma
marked this pull request as ready for review
March 23, 2026 21:35
lahma
enabled auto-merge (squash)
March 23, 2026 21:35
This was referenced Mar 27, 2026
This was referenced Jun 8, 2026
This was referenced Jun 29, 2026
This was referenced Jul 7, 2026
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.
for awaitinsideasync function*bodies never resumed after the iterator's.next()Promise resolved, leaving the outer.next()Promise permanently pending.Root cause
SuspendForAsyncIterationregisteredonFulfilled/onRejectedhandlers that calledAsyncGeneratorResumeNext(). That method exits early when_asyncGeneratorQueueis empty — which it always is at this point, because the current request was already dequeued before execution started. The generator body was left permanently suspended.Changes
AsyncGeneratorInstance: AddAsyncGeneratorContinueForAwait(PromiseCapability)— resumes the current request's execution directly (_asyncGeneratorState = Executing,_isResuming = true,ResumeExecution(capability)) without requiring a queued request.SuspendData: AddRejectedValuetoForAwaitSuspendDataso rejected iterator Promises can be propagated as throws on resume.JintForInForOfStatement.SuspendForAsyncIteration(async generator branch):_currentPromiseCapabilitybefore suspensionengine.AddToEventLoop(matching async function pattern for correct microtask ordering)AsyncGeneratorContinueForAwaitinstead ofAsyncGeneratorResumeNextRejectedValuein the rejection handlerJintForInForOfStatement.ExecuteInternal: On for-await-of resumption inside an async generator, checkForAwaitSuspendData.RejectedValueand throw it into the generator context.Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.