fix(memory): close embedded Hindsight async client cleanly (salvage #14605)#16209
Merged
Conversation
HindsightEmbedded.close() delegates to its sync client.close(). When Hermes created/used that client on the shared async loop, closing it from the main thread raises 'attached to a different loop' before aiohttp releases the session — so the ClientSession / TCPConnector leak past provider teardown. Close the embedded inner async client on the shared loop first via _run_sync(inner_client.aclose()), then let the wrapper's sync close() do its daemon/UI bookkeeping. Salvage of #14605: test placement rebased — appended TestShutdown class after TestSharedEventLoopLifecycle (which landed on main after the PR was written). Original author attribution preserved.
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.
HindsightEmbedded.close()delegates to its syncclient.close(). When Hermes created/used that client on the shared async loop, closing it from the main thread raisesattached to a different loopbefore aiohttp releases the session — so the ClientSession / TCPConnector leak past provider teardown.Fix closes the embedded inner async client on the shared loop first via
_run_sync(inner_client.aclose()), then lets the wrapper's syncclose()do its daemon/UI bookkeeping.Salvage of #14605 by @maxims-oss. Original author attribution preserved via rebase merge.
Salvage note
PR was stale on the test-file anchor:
TestSharedEventLoopLifecycle+TestAvailabilityexpansions landed on main after the PR was written (file grew 612 → 1104 lines). Rebased the newTestShutdownclass to append cleanly afterTestSharedEventLoopLifecycleinstead of in the middle. Production hunk was clean.Changes
shutdown()local_embeddedbranch: close inner async client on shared loop via_run_sync(inner_client.aclose())then null outself._client._clientbefore calling wrapperclose().TestShutdownclass withtest_local_embedded_shutdown_closes_inner_async_client_on_shared_loop.Validation
local_embeddedshutdownclose()→ RuntimeError swallowed, session leaksaclose()on shared loop → wrapperclose()→ cleanCloses #14605 (original PR, merged via salvage).