Skip to content

Commit 6ae261e

Browse files
committed
shield connection close in terminate
If terminate is called from an asyncio.CancelledError exception handler, under an anyio task group, await will bail with asyncio.CancelledError right away, leading to a connection leak. Shielding the close() call allows the connection to be properly closed in those cases.
1 parent ef23611 commit 6ae261e

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎lib/sqlalchemy/dialects/postgresql/asyncpg.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def terminate(self):
915915
try:
916916
# try to gracefully close; see #10717
917917
# timeout added in asyncpg 0.14.0 December 2017
918-
await_(self._connection.close(timeout=2))
918+
await_(asyncio.shield(self._connection.close(timeout=2)))
919919
except (
920920
asyncio.TimeoutError,
921921
asyncio.CancelledError,

0 commit comments

Comments
 (0)