Skip to content

gh-155143: Fix asyncio.shield leaking tasks via await-graph. - #155144

Open
pteromys wants to merge 2 commits into
python:mainfrom
pteromys:main
Open

gh-155143: Fix asyncio.shield leaking tasks via await-graph.#155144
pteromys wants to merge 2 commits into
python:mainfrom
pteromys:main

Conversation

@pteromys

@pteromys pteromys commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

There were two places where `cur_task` could live until `inner` ended:

1. `inner._asyncio_awaited_by`, and
2. as a capture in `_clear_awaited_by_callback` in `inner._callbacks`.
Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
test_utils.run_briefly(self.loop)
self.assertTrue(outer.cancelled())
self.assertEqual(0, 0 if outer._callbacks is None else len(outer._callbacks))
self.assertEqual(0, 0 if inner._asyncio_awaited_by is None else len(inner._asyncio_awaited_by))

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.

Suggested change
self.assertEqual(0, 0 if inner._asyncio_awaited_by is None else len(inner._asyncio_awaited_by))
self.assertFalse(inner._asyncio_awaited_by)

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.

Applied, thanks! Should we also apply the same simplification to the preceding line about outer._callbacks, or just leave it as-is since we wouldn't otherwise be changing it?

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
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.

2 participants