]> 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:33:49 +0000 (22:33 -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
(cherry picked from commit eff3aa8ad6bf74181280a85bf03d401126c65b01)

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 7e93b1232e10739d714a571a3e87a64454e750a9..85affdca3aaa401b35ab097466d7e349f2cc7aa5 100644 (file)
@@ -890,7 +890,7 @@ class AsyncAdapt_asyncpg_connection(AdaptedConnection):
                 # try to gracefully close; see #10717
                 # timeout added in asyncpg 0.14.0 December 2017
                 self.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