]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
asyncpg: shield connection close in terminate to avoid connection leak
authorFederico Caselli <cfederico87@gmail.com>
Fri, 17 Jan 2025 20:16:51 +0000 (21:16 +0100)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 20 Jan 2025 18:06:08 +0000 (13:06 -0500)
Added an additional ``shield()`` call within the connection terminate
process of the asyncpg driver, to mitigate an issue where terminate would
be prevented from completing under the anyio concurrency library.

Fixes #12077
Closes: #12076
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12076
Pull-request-sha: 6ae261ea7668f4c850874666efec6fef658b08c0

Change-Id: Iaec63d02b620201dc60ffdad76ba9d61d427cac1
(cherry picked from commit 2f6ca6554ddd725849dd6b2d32bf495391087bec)

doc/build/changelog/unreleased_20/12077.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/postgresql/asyncpg.py

diff --git a/doc/build/changelog/unreleased_20/12077.rst b/doc/build/changelog/unreleased_20/12077.rst
new file mode 100644 (file)
index 0000000..ac1c5a9
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: postgresql, usecase, asyncio
+    :tickets: 12077
+
+    Added an additional ``shield()`` call within the connection terminate
+    process of the asyncpg driver, to mitigate an issue where terminate would
+    be prevented from completing under the anyio concurrency library.
index 523c47abcd0116f5b7b193052ac262987eb1cc72..0cc1e99cca86befc0ab162f9b3194984d1a5b3a7 100644 (file)
@@ -904,7 +904,7 @@ class AsyncAdapt_asyncpg_connection(AdaptedConnection):
             try:
                 # try to gracefully close; see #10717
                 # timeout added in asyncpg 0.14.0 December 2017
-                self.await_(self._connection.close(timeout=2))
+                self.await_(asyncio.shield(self._connection.close(timeout=2)))
             except (
                 asyncio.TimeoutError,
                 asyncio.CancelledError,