From: Daniele Varrazzo Date: Sat, 19 Feb 2022 16:34:37 +0000 (+0100) Subject: fix(pool): set the open flag before starting the maintenance tasks X-Git-Tag: pool-3.1.1~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=287ecf3f1bff3c39e92c25357d154ebc624ca075;p=thirdparty%2Fpsycopg.git fix(pool): set the open flag before starting the maintenance tasks Failing to do so we might trigger the test in `MaintenanceTask.run()` and find the pool closed, so discard the operation. It usually doesn't happen, but with a few combination of IO operation it does happen: see https://github.com/psycopg/psycopg/issues/230 for details. --- diff --git a/docs/news_pool.rst b/docs/news_pool.rst index e684f8068..a059c7b88 100644 --- a/docs/news_pool.rst +++ b/docs/news_pool.rst @@ -7,6 +7,16 @@ ``psycopg_pool`` release notes ============================== +Future releases +--------------- + +psycopg_pool 3.1.1 (unreleased) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Fix race condition on pool creation which might result in the pool not + filling (:ticket:`#230`). + + Current release --------------- @@ -26,6 +36,7 @@ psycopg_pool 3.0.3 set to 0 (instead of hanging). - Raise `PoolClosed` calling `~ConnectionPool.wait()` on a closed pool. + psycopg_pool 3.0.2 ^^^^^^^^^^^^^^^^^^ diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index d29092f15..20ba8c109 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -257,12 +257,12 @@ class ConnectionPool(BasePool[Connection[Any]]): self._check_open() - self._start_workers() - self._start_initial_tasks() - self._closed = False self._opened = True + self._start_workers() + self._start_initial_tasks() + def _start_workers(self) -> None: self._sched_runner = threading.Thread( target=self._sched.run, diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index b8b6af937..ce26b2cf2 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -197,12 +197,12 @@ class AsyncConnectionPool(BasePool[AsyncConnection[Any]]): self._check_open() - self._start_workers() - self._start_initial_tasks() - self._closed = False self._opened = True + self._start_workers() + self._start_initial_tasks() + def _start_workers(self) -> None: self._sched_runner = create_task( self._sched.run(), name=f"{self.name}-scheduler"