Avoid stack overflow in nested asyncio task chains - #704
Merged
davidhewitt merged 2 commits intoAug 17, 2026
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merging this PR will not alter performance
Comparing Footnotes
|
rewitt94
approved these changes
Aug 10, 2026
rewitt94
left a comment
Contributor
There was a problem hiding this comment.
Thanks for contributing! This looks good to me!
Contributor
Author
Open
Contributor
|
Thanks @jay3cx! I will forward this to @davidhewitt |
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.
The waiter-error path re-entered
VM::handle_exceptionrecursively, adding one native Rust stack frame for each nestedasyncio.gatherwaiter.This changes waiter error propagation to an iterative loop while preserving the existing exception handling and ownership behavior.
A regression test covers a 4,000-level nested
asyncio.gatherchain and verifies that the originalValueErrorremains catchable.Tests
cargo test -p monty --test asynciocargo test -p montyFixes #649
Summary by cubic
Prevents stack overflow when exceptions propagate through deep
asyncio.gatherwaiter chains by switching from recursive to iterative handling. Preserves exception behavior; adds a regression test.handle_exception_with_valueiterative via a loop overhandle_exception_step.ExceptionHandlingResultwithCaught,Unhandled, andPropagateToWaiterto control propagation and handle waiter handoff without growing the stack.asyncio.gather; verifies the originalValueErroris catchable.Written for commit 4f92024. Summary will update on new commits.