Skip to content

Fix spurious "Future exception was never retrieved" warnings for connection lost errors #11100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2025

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented May 31, 2025

What do these changes do?

This PR fixes spurious "Future exception was never retrieved" warnings that occur when connections are lost (e.g., SSL shutdown timeouts, network errors) and the connector is not immediately closed.

The fix marks the exception on the ResponseHandler.closed future as retrieved after setting it, since the exception is always propagated through other means (via the waiter). This prevents Python from logging unnecessary warnings about unretrieved exceptions.

Are there changes in behavior for the user?

No functional changes. Users will no longer see spurious "Future exception was never retrieved" warnings in their logs when connections are lost.

Related issue number

This issue was introduced by #3733 (backported as #11074), which added proper connection closure waiting but exposed these futures that may not be awaited until the connector is closed.

bdraco added 2 commits May 30, 2025 23:44
…ctions

TimeoutError: SSL shutdown timed out

The above exception was the direct cause of the following exception:

aiohttp.client_exceptions.ClientConnectionError: Connection lost: SSL shutdown timed out
@bdraco bdraco changed the title Handle spurious Future exception was never retrieved for closed connections Fix spurious "Future exception was never retrieved" warnings for connection lost errors May 31, 2025
Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.82%. Comparing base (4351c13) to head (7a9c19d).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11100   +/-   ##
=======================================
  Coverage   98.82%   98.82%           
=======================================
  Files         129      129           
  Lines       41493    41505   +12     
  Branches     2234     2234           
=======================================
+ Hits        41007    41019   +12     
  Misses        337      337           
  Partials      149      149           
Flag Coverage Δ
CI-GHA 98.71% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.42% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.68% <100.00%> (-0.02%) ⬇️
OS-macOS 97.61% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.38% <100.00%> (-0.02%) ⬇️
Py-3.10.17 97.89% <100.00%> (+<0.01%) ⬆️
Py-3.11.12 98.06% <100.00%> (-0.01%) ⬇️
Py-3.11.9 97.56% <100.00%> (-0.01%) ⬇️
Py-3.12.10 98.46% <100.00%> (+<0.01%) ⬆️
Py-3.13.3 98.44% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.27% <100.00%> (-0.01%) ⬇️
Py-3.9.22 97.77% <100.00%> (-0.01%) ⬇️
Py-pypy7.3.16 93.44% <100.00%> (-0.43%) ⬇️
VM-macos 97.61% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.42% <100.00%> (+<0.01%) ⬆️
VM-windows 96.68% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 31, 2025
@bdraco bdraco marked this pull request as ready for review May 31, 2025 04:51
@bdraco bdraco requested review from webknjaz and asvetlov as code owners May 31, 2025 04:51
@bdraco bdraco added backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot backport-3.13 Trigger automatic backporting to the 3.13 release branch by Patchback robot labels May 31, 2025
Copy link

codspeed-hq bot commented May 31, 2025

CodSpeed Performance Report

Merging #11100 will not alter performance

Comparing closed_exc (7a9c19d) with master (4351c13)

Summary

✅ 59 untouched benchmarks

@bdraco bdraco enabled auto-merge (squash) May 31, 2025 04:56
@bdraco bdraco merged commit 947247f into master May 31, 2025
41 of 43 checks passed
@bdraco bdraco deleted the closed_exc branch May 31, 2025 05:01
Copy link
Contributor

patchback bot commented May 31, 2025

Backport to 3.12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.12/947247fd4aa2954a746c3a8c183bb7acceb8c3cd/pr-11100

Backported as #11101

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Copy link
Contributor

patchback bot commented May 31, 2025

Backport to 3.13: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.13/947247fd4aa2954a746c3a8c183bb7acceb8c3cd/pr-11100

Backported as #11102

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request May 31, 2025
bdraco added a commit that referenced this pull request May 31, 2025
…s never retrieved" warnings for connection lost errors (#11101)

Co-authored-by: J. Nick Koston <[email protected]>
bdraco added a commit that referenced this pull request May 31, 2025
…s never retrieved" warnings for connection lost errors (#11102)

Co-authored-by: J. Nick Koston <[email protected]>
# The exception is always passed on through
# other means, so this is safe
with suppress(Exception):
self.closed.exception()
Copy link
Member

Choose a reason for hiding this comment

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

Should this maybe be handled by the set_exception() helper?

I assume that function is the one responsible for sending the exception elsewhere, so seems to me that it'd make sense for it to also suppress the unretrieved exception that it's handling.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case it's the waiter below that is responsible for propagating the exception. We effectively have it in two places. There are other places where we don't so we can't make set_exception responsible as it doesn't know if it should suppress the warning or not

bdraco added a commit that referenced this pull request Jun 1, 2025
This is a followup to #11100 and #3733 to avoid creating closed futures
that will never be awaited.
bdraco added a commit that referenced this pull request Jun 1, 2025
This is a followup to #11100 and #3733 to avoid creating closed futures
that will never be awaited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot backport-3.13 Trigger automatic backporting to the 3.13 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants