agents
agents copied to clipboard
ConnectionPool.aclose() can leave a connection open when get() is in flight
Reproduction
Reproduced on main at 77d67650f5743a197c3ebe9e8908c4980ff8acc2 with Python 3.12 on Windows.
- Start
ConnectionPool.get()with aconnect_cbblocked on anasyncio.Event. - Call
aclose()while the handshake is blocked. It returns immediately. - Release the handshake.
_connect()sees the changed invalidation generation, closes the first result, and retries. The replacement remains open after shutdown.
An event-driven test also reproduces the early return when get() is blocked draining a queued connection.
Expected behavior
aclose() should account for connections created by acquisitions already in progress before it returns.
Related work
#8244 already proposes a fix. I independently verified that both regressions fail on the base revision and that all 19 connection-pool unit tests pass with its patch.