pg.ddx.io  psycopg/psycopg GitHub issues and pull requests  
help / color / mirror / Atom feed
From: ericdelorefice (@ericdelorefice) <noreply+ericdelorefice@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: [psycopg/psycopg] issue #1475: pool.wait() raises AssertionError after a previous wait() was cancelled
Date: Tue, 03 Nov 2026 12:53:27 +0000
Message-ID: <gh-psycopg-psycopg-1475@github.com> (raw)

If the task running `pool.wait()` (or `open(wait=True)`) is cancelled, for example by a task group or a shutdown, `_pool_full_event` is never reset, because the reset after `wait_timeout()` only runs on a normal return. From then on every `wait()` and `open(wait=True)` fails on `assert not self._pool_full_event`, even once the pool is full, since the assert comes before the "already full" check. `connection()` keeps working.

This is not the concurrent case from #515: the calls are sequential, and the first `wait()` has already ended by cancellation before the next one starts.

```python
import asyncio
import psycopg_pool

async def slow_configure(conn):
    await asyncio.sleep(0.5)  # pool takes a while to fill

async def main():
    async with psycopg_pool.AsyncConnectionPool(
        "", min_size=2, configure=slow_configure
    ) as pool:
        t = asyncio.create_task(pool.wait())
        await asyncio.sleep(0.1)
        t.cancel()
        try:
            await t
        except asyncio.CancelledError:
            pass
        await asyncio.sleep(2)  # the pool is full by now
        await pool.wait()  # AssertionError

asyncio.run(main())
```

```
  File ".../psycopg_pool/pool_async.py", line 191, in wait
    assert not self._pool_full_event
AssertionError
```

Without the cancel the second `wait()` returns normally. psycopg-pool 3.3.3, psycopg 3.3.6, Python 3.15, PostgreSQL 18; same code on master. pool.py and both null pools have the same code (in the sync pool, a caught Ctrl-C during `wait()` does it).

The reset should happen in a finally. Happy to send a PR.


view thread (3+ messages)  latest in thread

Message-ID: <gh-psycopg-psycopg-1475@github.com>
Permalink:  ../gh-psycopg-psycopg-1475@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox