-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
BugFix in aiohttp.ClientSession that caused "Unclosed connector" warnings #11696
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
base: master
Are you sure you want to change the base?
BugFix in aiohttp.ClientSession that caused "Unclosed connector" warnings #11696
Conversation
CodSpeed Performance ReportMerging #11696 will improve performances by 12.65%Comparing Summary
Benchmarks breakdown
Footnotes |
for more information, see https://pre-commit.ci
| ) | ||
|
|
||
| if connector is None: | ||
| connector_owner = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is the only line that is potentially related to the title of this PR? Though surely only fixing an issue where someone incorrectly passes connector_owner=False without a connector (in which case we should probably error on the incorrect arguments, rather than just override it).
|
We'll need a regression test that reproduces the reported issue too. |
What do these changes do?
These changes fix a bug in
aiohttp.ClientSessionthat caused "Unclosed connector" warnings when a user-provided connector was used.The session now correctly distinguishes between internally created and externally provided connectors, ensuring it only closes connectors that it owns.
Are there changes in behavior for the user?
Yes, there is a positive change in behavior.
Users who provide their own
TCPConnectorinstance to aClientSessionwill no longer seeResourceWarning: Unclosed connectorwarnings when the session is closed.The lifecycle of the external connector remains entirely under the user’s control, as expected.
The behavior for internally created connectors is unchanged.
Is it a substantial burden for the maintainers to support this?
No, this change should not be a burden to maintain.
It corrects the logic to align with the library’s intended design and documentation.
The fix is:
ClientSession’s__init__andclosemethods.This should be easy to support long-term.
Related issue number
"2e6: With explicit connector reuse, aiohttp.ClientSession fails to close connector when using async context"