Skip to content

gh-156321: Don't eagerly log exceptions from a cancelled asyncio.shield() - #158590

Merged
kumaraditya303 merged 1 commit into
python:mainfrom
kumaraditya303:gh-156321-shield-log
Oct 2, 2026
Merged

kumaraditya303 merged 1 commit into
python:mainfrom
kumaraditya303:gh-156321-shield-log

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

…o.shield()

When the outer future returned by shield() was cancelled, a callback was
added to the inner future that reported its exception through the loop
exception handler as soon as it completed, even if the exception was
retrieved afterwards by awaiting the inner future or calling
`exception()`. Remove the callback; an exception nobody retrieves is
still reported by the inner future itself when it is garbage collected,
like any other future.

@carltongibson carltongibson 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.

Thanks for making this PR so quickly @kumaraditya303 🎁

Just to confirm, this resolves the issue as observed in asgiref. 👍

@kumaraditya303
kumaraditya303 merged commit 2095eab into python:main Oct 2, 2026
59 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@kumaraditya303
kumaraditya303 deleted the gh-156321-shield-log branch October 2, 2026 12:57
@bedevere-app

bedevere-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

GH-158598 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 2, 2026
@bedevere-app

bedevere-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

GH-158599 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 2, 2026
kumaraditya303 added a commit that referenced this pull request Oct 2, 2026
…io.shield() (GH-158590) (#158599)

gh-156321: Don't eagerly log exceptions from a cancelled asyncio.shield() (GH-158590)

When the outer future returned by shield() was cancelled, a callback was
added to the inner future that reported its exception through the loop
exception handler as soon as it completed, even if the exception was
retrieved afterwards by awaiting the inner future or calling
`exception()`. Remove the callback; an exception nobody retrieves is
still reported by the inner future itself when it is garbage collected,
like any other future.
(cherry picked from commit 2095eab)

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