]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix(pool): fix race in the construction of the sync ConnectionPool lock 1301/head
authorOliver Haas <ohaas@e1plus.de>
Thu, 30 Apr 2026 07:52:16 +0000 (09:52 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 1 May 2026 20:38:26 +0000 (22:38 +0200)
commitaee0bf2659db77c31154acf583baf0a98675c192
tree05260238d353eb5f39344674d0ed9fdda4ea6c3f
parentbc4d30375557fc32f2a91c2f8b75a5d21711ea89
fix(pool): fix race in the construction of the sync ConnectionPool lock

The lock used to make `ConnectionPool.open()` thread-safe was itself
constructed lazily in `_ensure_lock()` without any guard. Two threads
racing the first `open()` could each create a different `Lock`, defeat
the mutual exclusion in `_open()`, both pass the `_closed` guard, and
both call `_start_workers()`. The second one tripped
`assert not self._workers`.

Construct the sync lock eagerly in `__init__`. The async lock must stay
lazy because `asyncio.Lock` binds to the running event loop.
docs/news_pool.rst
psycopg_pool/psycopg_pool/pool.py
psycopg_pool/psycopg_pool/pool_async.py