fix: close remote-loop transports instead of firing and forgetting - #39
Open
dfguerrerom wants to merge 2 commits into
Open
fix: close remote-loop transports instead of firing and forgetting#39dfguerrerom wants to merge 2 commits into
dfguerrerom wants to merge 2 commits into
Conversation
aclose() scheduled client.aclose() on another loop and dropped the future, so a loop that stopped right after the scheduling succeeded left its sockets open. It now waits on that close and releases the sockets directly when the loop will not run again. Also folds credential refresh into one cross-loop single-flight, and reads the pooled socket through the network stream's accessor instead of walking anyio's wrapper layout. Follow-up from a Codex review of #38.
The two are the same class only from 3.11; before that the futures one derives from Exception, so pytest.raises(TimeoutError) let it through and the test failed on 3.9 and 3.10.
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.
Follow-up from a Codex review of #38, which found a real defect in what merged there.
aclose()scheduledclient.aclose()on another live loop withrun_coroutine_threadsafeand dropped the returned future. Scheduling can succeed just before a queuedloop.stop(), so that close never ran and the pool's sockets stayed open — a leak on exactly the teardown path meant to prevent one.await_remote_close()now waits on the future, and when the target loop is no longer running it cancels and callsrelease_sockets()directly. The regression test blocks the private loop, queuesstop()ahead of the close, and asserts the real pooled descriptors end up closed.Two smaller items, both residuals called out in #38:
AsyncSingleFlightfolds credential refresh into one shared operation across loops, so two loops no longer each refresh the token. The per-loopauth_refresh_lockstill coalesces within a loop.release_sockets()now reads the socket via the network stream'sget_extra_info("socket"), keeping the anyio wrapper walk only as a fallback. Less private-layout dependence.test_a_closed_loop_releases_its_resourceswas also strengthened to assert the spent loops' descriptors are actually closed, rather than just that the registry shrank.One trade-off worth a reviewer's eye: single-flight makes followers wait on the leader's refresh, so if the leader's loop dies mid-refresh the followers wait on a future that never resolves. The window is one short token request, and the previous behaviour traded that risk for duplicate refreshes. Flagging it rather than changing it.
Tests: 113 pass (109 before), stable over 5 consecutive runs of the concurrency file.