]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix(pool): set the open flag before starting the maintenance tasks
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 19 Feb 2022 16:34:37 +0000 (17:34 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 19 Feb 2022 16:39:10 +0000 (17:39 +0100)
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.

docs/news_pool.rst
psycopg_pool/psycopg_pool/pool.py
psycopg_pool/psycopg_pool/pool_async.py

index e684f80685a2898f248aaf23f76d5ec0849e7fc6..a059c7b88746fc0d356e43d3036aa874650fcc7c 100644 (file)
@@ -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
 ^^^^^^^^^^^^^^^^^^
 
index d29092f15d2bd8d4ab2e5fbf47fa64d9d66fb586..20ba8c109d8cb90147adabc73c01206a0ac238ca 100644 (file)
@@ -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,
index b8b6af93734edd5f1e6cd75d737e9606190ce8a7..ce26b2cf2741bf233ab496d6808cfd2d10c6943d 100644 (file)
@@ -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"