Skip to content

Commit 6f22ad8

Browse files
committed
Add test for acquire connection leak
1 parent 2646c81 commit 6f22ad8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/test_pool.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,26 @@ async def worker():
379379
self.cluster.trust_local_connections()
380380
self.cluster.reload()
381381

382+
async def test_pool_handles_task_cancel_in_acquire_with_timeout(self):
383+
# See https://github.com/MagicStack/asyncpg/issues/547
384+
pool = await self.create_pool(database='postgres',
385+
min_size=1, max_size=1)
386+
387+
async def worker():
388+
async with pool.acquire(timeout=100):
389+
pass
390+
391+
# Schedule task
392+
task = self.loop.create_task(worker())
393+
# Yield to task, but cancel almost immediately
394+
await asyncio.sleep(0.00000000001)
395+
# Cancel the worker.
396+
task.cancel()
397+
# Wait to make sure the cleanup has completed.
398+
await asyncio.sleep(0.4)
399+
# Check that the connection has been returned to the pool.
400+
self.assertEqual(pool._queue.qsize(), 1)
401+
382402
async def test_pool_handles_task_cancel_in_release(self):
383403
# Use SlowResetConnectionPool to simulate
384404
# the Task.cancel() and __aexit__ race.

0 commit comments

Comments
 (0)