From: Mike Bayer Date: Thu, 11 Jan 2024 03:31:59 +0000 (-0500) Subject: catch OSError (base of ConnectionError) and asyncpg errors for terminate X-Git-Tag: rel_2_0_26~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e525704800bbc483b4ca22997157d75bc90b9a41;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git catch OSError (base of ConnectionError) and asyncpg errors for terminate 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) --- diff --git a/doc/build/changelog/unreleased_20/10863.rst b/doc/build/changelog/unreleased_20/10863.rst new file mode 100644 index 0000000000..df722f8fe4 --- /dev/null +++ b/doc/build/changelog/unreleased_20/10863.rst @@ -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. + diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py index 7e93b1232e..85affdca3a 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -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