From: Daniele Varrazzo Date: Wed, 5 Jan 2022 01:50:25 +0000 (+0100) Subject: Add ConnectionTimeout subclass of OperationalError X-Git-Tag: pool-3.1~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75189c66073fbfd97b6caadbc5960d664b9ff3e4;p=thirdparty%2Fpsycopg.git Add ConnectionTimeout subclass of OperationalError To be used in the connection pool to detect timeout on connection. Backported to Psycopg 3.0.8 to allow the pool 3.1 to work with it, at least on diminished capacity (NullPool.connection() would time out only for clients in the queue, not in case of new connection timeout). --- diff --git a/psycopg/psycopg/errors.py b/psycopg/psycopg/errors.py index 9054c31ec..18bbda3fd 100644 --- a/psycopg/psycopg/errors.py +++ b/psycopg/psycopg/errors.py @@ -168,6 +168,12 @@ class NotSupportedError(DatabaseError): __module__ = "psycopg" +class ConnectionTimeout(OperationalError): + """ + Exception raised on timeout connection. + """ + + class Diagnostic: """Details from a database error report.""" diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index f236102c9..de55f43e1 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -91,7 +91,7 @@ def wait_conn(gen: PQGenConn[RV], timeout: Optional[float] = None) -> RV: rlist = sel.select(timeout=timeout) sel.unregister(fileno) if not rlist: - raise e.OperationalError("timeout expired") + raise e.ConnectionTimeout("connection timeout expired") ready: Ready = rlist[0][1] # type: ignore[assignment] fileno, s = gen.send(ready) @@ -201,7 +201,7 @@ async def wait_conn_async( fileno, s = gen.send(ready) except TimeoutError: - raise e.OperationalError("timeout expired") + raise e.ConnectionTimeout("connection timeout expired") except StopIteration as ex: rv: RV = ex.args[0] if ex.args else None