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-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eff3aa8ad6bf74181280a85bf03d401126c65b01;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 --- 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 a4d47b0225..fe6f17a74f 100644 --- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py +++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py @@ -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