Repository navigation
Wait for a connection closure with timeout - #15
Merged
Merged
Conversation
slawwan
marked this pull request as ready for review
October 25, 2026 10:19
Pliner
approved these changes
Oct 25, 2026
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 to #8: as suggested there, the background closure is dropped now that MagicStack/asyncpg#1361 is released in asyncpg 0.32.0.
The guard awaits
connection.close(timeout=close_timeout)(5 s by default). Since 0.32.0, the timeout also covers the pending cancellation, and on timeout asyncpg aborts the socket. Before, the backgroundclose()on a silently dead connection could hang forever and keep the socket open.Errors from
close()are suppressed, so they never replace the original exception. Otherwise aTimeoutErrorfrom closing a dead connection swallowsCancelledError, and the cancelled guard keeps running and reacquires the lock.asyncpg 0.32.0 is required: with 0.31.0 the awaited
close()hangs again,test_reacquire_lock_after_silent_disruptionand the new tests fail.Tests:
test_release_silently_dead_connection: the guard drops a silently dead connection; fails onmain, passes with the fix;test_stop_on_silently_dead_connection: the guard stops on cancellation while its connection is silently dead; passes onmain, fails ifclose()errors are not suppressed.