]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
catch OSError (base of ConnectionError) and asyncpg errors for terminate
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Jan 2024 03:31:59 +0000 (22:31 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Jan 2024 03:32:54 +0000 (22:32 -0500)
Fixed regression in the asyncpg dialect caused by :ticket:`10717` in
release 2.0.24 where the change that now attempts to gracefully close the
asyncpg connection before terminating would not fall back to
``terminate()`` for other potential connection-related exceptions other
than a timeout error, not taking into account cases where the graceful
``.close()`` attempt fails for other reasons such as connection errors.

Fixes: #10863
Change-Id: If1791bce26803f92547cdf26fb641996c7f638fa

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

diff --git a/doc/build/changelog/unreleased_20/10863.rst b/doc/build/changelog/unreleased_20/10863.rst
new file mode 100644 (file)
index 0000000..df722f8
--- /dev/null
@@ -0,0 +1,11 @@
+.. change::
+    :tags: bug, regression, postgresql
+    :tickets: 10863
+
+    Fixed regression in the asyncpg dialect caused by :ticket:`10717` in
+    release 2.0.24 where the change that now attempts to gracefully close the
+    asyncpg connection before terminating would not fall back to
+    ``terminate()`` for other potential connection-related exceptions other
+    than a timeout error, not taking into account cases where the graceful
+    ``.close()`` attempt fails for other reasons such as connection errors.
+
index a4d47b0225db02529914a771fcc7756b81bfc545..fe6f17a74fd875434e539e88fc5db387e378b911 100644 (file)
@@ -927,7 +927,7 @@ class AsyncAdapt_asyncpg_connection(AsyncAdapt_dbapi_connection):
                 # try to gracefully close; see #10717
                 # timeout added in asyncpg 0.14.0 December 2017
                 await_(self._connection.close(timeout=2))
-            except asyncio.TimeoutError:
+            except (asyncio.TimeoutError, OSError, self.dbapi.PostgresError):
                 # in the case where we are recycling an old connection
                 # that may have already been disconnected, close() will
                 # fail with the above timeout.  in this case, terminate