fix(smithy-http): auto-close aiohttp session to avoid unclosed warnings#711
Open
Alan4506 wants to merge 1 commit into
Open
fix(smithy-http): auto-close aiohttp session to avoid unclosed warnings#711Alan4506 wants to merge 1 commit into
Alan4506 wants to merge 1 commit into
Conversation
2e033e1 to
b069050
Compare
ubaskota
reviewed
Jun 5, 2026
| """ | ||
| connector = session.connector | ||
| if connector is not None and not connector.closed: | ||
| connector._close() # type: ignore[attr-defined] |
Contributor
There was a problem hiding this comment.
Why are you using an internal private method _close()?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
The
AIOHTTPClientnever closes itsaiohttp.ClientSession. Because the generated client deep-copies its config (and thus the transport) on every operation call, each call produced a throwaway session copy. On garbage collection these emitUnclosed client session/Unclosed connectorwarnings that print to stderr.Description of changes:
ClientSessionacross__deepcopy__instead of copying it, so that all per-call copies of the transport point to the same session.weakref.finalizehook that closes the underlying connector when the client is garbage collected (or at interpreter exit). The connector is closed synchronously because no event loop may be running at finalization. Closing it also marks the session as closed, so both warnings are suppressed.Testing:
Verified with the generated DynamoDB client running the example below (create table → put item → get item → delete table):
Before:
After:
Also ran the full
smithy-httptest suite: 334 passed, 3 skipped.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.