Skip to content

add CancelledError to list of exceptions caught in terminate #11821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zzzeek opened this issue Sep 2, 2024 Discussed in #11761 · 2 comments
Closed

add CancelledError to list of exceptions caught in terminate #11821

zzzeek opened this issue Sep 2, 2024 Discussed in #11761 · 2 comments
Labels
asyncio bug Something isn't working near-term release addition to the milestone which indicates this should be in a near-term release postgresql
Milestone

Comments

@zzzeek
Copy link
Member

zzzeek commented Sep 2, 2024

Discussed in #11761

diff --git a/lib/sqlalchemy/dialects/postgresql/asyncpg.py b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
index cb6b75154..40794e1dd 100644
--- a/lib/sqlalchemy/dialects/postgresql/asyncpg.py
+++ b/lib/sqlalchemy/dialects/postgresql/asyncpg.py
@@ -902,6 +902,7 @@ class AsyncAdapt_asyncpg_connection(AsyncAdapt_dbapi_connection):
                 await_(self._connection.close(timeout=2))
             except (
                 asyncio.TimeoutError,
+                asyncio.CancelledError,
                 OSError,
                 self.dbapi.asyncpg.PostgresError,
             ):
@zzzeek zzzeek added bug Something isn't working postgresql asyncio near-term release addition to the milestone which indicates this should be in a near-term release labels Sep 2, 2024
@zzzeek zzzeek added this to the 2.0.x milestone Sep 2, 2024
@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the main branch:

add asyncio.CancelledError to terminate conditions https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5482

@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the rel_2_0 branch:

add asyncio.CancelledError to terminate conditions https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/5483

sqlalchemy-bot pushed a commit that referenced this issue Sep 3, 2024

Verified

This commit was signed with the committer’s verified signature.
bcomnes Bret Comnes
Revising the asyncpg ``terminate()`` fix first made in 🎫`10717`
which improved the resiliency of this call under all circumstances, adding
``asyncio.CancelledError`` to the list of exceptions that are intercepted
as failing for a graceful ``.close()`` which will then proceed to call
``.terminate()``.

Fixes: #11821
Change-Id: Ic5e21cd18cc5517aae372560c52b2b2396c65483
(cherry picked from commit dc7aec4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asyncio bug Something isn't working near-term release addition to the milestone which indicates this should be in a near-term release postgresql
Projects
None yet
Development

No branches or pull requests

2 participants