From: Daniele Varrazzo Date: Thu, 16 Mar 2023 21:15:51 +0000 (+0100) Subject: fix(pool): reinforce handling of errors in queued clients X-Git-Tag: pool-3.1.7~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ff5f290a77173b3e7c6254a3bfb49dc3ea48d6f;p=thirdparty%2Fpsycopg.git fix(pool): reinforce handling of errors in queued clients Unlike the async counterpart, I have no idea how to test this condition, because I don't think you can cancel a Python thread. I could put the pool and the first client in threads and use the main thread as queued client, but it seems pretty convoluted. However, an error handling in the same place that fixed #509 in the async pools doesn't hurt. --- diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index dd50d73a6..498ef7020 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -714,7 +714,7 @@ class WaitingClient: def __init__(self) -> None: self.conn: Optional[Connection[Any]] = None - self.error: Optional[Exception] = None + self.error: Optional[BaseException] = None # The WaitingClient behaves in a way similar to an Event, but we need # to notify reliably the flagger that the waiter has "accepted" the @@ -730,10 +730,13 @@ class WaitingClient: """ with self._cond: if not (self.conn or self.error): - if not self._cond.wait(timeout): - self.error = PoolTimeout( - f"couldn't get a connection after {timeout} sec" - ) + try: + if not self._cond.wait(timeout): + self.error = PoolTimeout( + f"couldn't get a connection after {timeout} sec" + ) + except BaseException as ex: + self.error = ex if self.conn: return self.conn