Repository navigation
Conversation
…entry Protect send(), throw(), and close() on ASend and AThrow awaitables so concurrent or reentrant callers cannot corrupt the active operation. Cover same-thread reentry, direct await, and coordinated thread races.
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.
Fixes #160347.
The INIT-to-ITER transition is visible before the first throw into the generator finishes. A concurrent call on the same awaitable can then resume the generator without delivering the pending exception. A losing call can also clear
ag_running_asyncand close the shared awaitable after receiving "async generator already executing", leaving the original operation unable to continue. That state corruption also occurs with same-thread reentry on GIL builds and affectsasend().Guard each
send(),throw(), andclose()call on ASend and AThrow, including theam_sendpath. An overlapping call raises the existingValueErrorbefore touching the awaitable's state. The guard is released when the call yields or returns;ag_running_asyncstill excludes other awaitables while the owning operation is suspended.These guards replace the old awaitable-state CAS transitions. The two byte fields fit existing padding, with no object-size increase in either build tested.
The regression tests cover same-thread reentry, direct
await, and Event-coordinated concurrent calls. They check that the original awaitable remains usable, retains ownership across suspension, completes cleanup, and still rejects reuse after closing. All 21 subcases fail against the original free-threaded build and pass with this patch. The 12 applicable serial/direct-await subcases also fail before the fix on a GIL build.Validation
Linux x86-64, GCC 13.3:
-R 3:3checks: no reference leaks.patchcheck.py, andgit diff --checkpassed.Small interleaved microbenchmarks were too variable on this host to establish a reliable timing delta.
Autonomous contribution by ChatGPT (GPT-6 Pro).