Skip to content

gh-158688: Fix crash when dumping a deep chain of awaiting tasks - #158960

Closed
deadlovelll wants to merge 5 commits into
python:mainfrom
deadlovelll:gh-158688-recursion-v2
Closed

deadlovelll wants to merge 5 commits into
python:mainfrom
deadlovelll:gh-158688-recursion-v2

Conversation

@deadlovelll

Copy link
Copy Markdown
Contributor

Fix crash when dumping a deep chain of awaiting tasks

For details see gh-158688

@deadlovelll

Copy link
Copy Markdown
Contributor Author

@maurycy happy to see your review here =)

@maurycy

maurycy commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@deadlovelll Thank you! I will try to do so over the weekend.

self.assertEqual(asyncio.run(rec(3)), ["rec"] * 4)

@skip_if_not_supported
def test_deep_awaiter_chain_is_walked_fully(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a graph where two waiters share the same parent? Both changed tests still pass without the seen set. The extra b task does not make the walk visit a task twice.

My shared-parent check returns root, p, q, shared, shared without seen. It returns four unique tasks with this patch. A cycle case can also check that the walk terminates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. just pushed the change!

@maurycy maurycy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deadlovelll Does the crash still happen after merging #153365? My understanding is that we only get RuntimeError, and the visited set was added in #161508. And, if I'm reading the PR right, it effectively removes the 16384 limit for get_async_stack_trace() and keeps it only for futures from get_all_awaited_by().

@deadlovelll

Copy link
Copy Markdown
Contributor Author

@deadlovelll Does the crash still happen after merging #153365? My understanding is that we only get RuntimeError, and the visited set was added in #161508. And, if I'm reading the PR right, it effectively removes the 16384 limit for get_async_stack_trace() and keeps it only for futures from get_all_awaited_by().

yeah, segfault disappeared. but i thought about limits.. if we already handles cycles and repeated visitis, do we still need a hard limit? Maybe i'm missig something

@maurycy

maurycy commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

@deadlovelll

do we still need a hard limit?

I'd say so. Other walks are bounded (MAX_FRAME_CHAIN_DEPTH, MAX_SET_TABLE_SIZE etc.) and the visited set still doesn't guarantee bounded walk. Also, even if we ignore adversarial targets, the most interesting argument is that we read the memory of a remote process in a non-atomic way so we can always get a torn read (the data changes under us.) (We had a reverse situation in the CI!) Perhaps we should just bump it? Buildbots should be kept in mind.

@pablogsal

Copy link
Copy Markdown
Member

Since #153365 fixed the crash, can you update the title, description, and NEWS entry to describe the proposed limit change? What workload needs more than 16,384 tasks? The visited set skips repeated tasks. We still need a hard limit on how many distinct tasks one call can visit.

@deadlovelll

Copy link
Copy Markdown
Contributor Author

@deadlovelll

do we still need a hard limit?

I'd say so. Other walks are bounded (MAX_FRAME_CHAIN_DEPTH, MAX_SET_TABLE_SIZE etc.) and the visited set still doesn't guarantee bounded walk. Also, even if we ignore adversarial targets, the most interesting argument is that we read the memory of a remote process in a non-atomic way so we can always get a torn read (the data changes under us.) (We had a reverse situation in the CI!) Perhaps we should just bump it? Buildbots should be kept in mind.

thank you for explanation, that makes sense. regarding the limit increase I think this needs to be tested in practice, I haven’t done that yet. In any case, this topic probably warrants a separate issue.

as for this pr, it seems to have run its course, since it addressed things that have already been fixed. If you agree, I’ll close it.

@pablogsal

Copy link
Copy Markdown
Member

Yes, please close this one. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants