Skip to content

Commit b5b1c99

Browse files
committed
pool: Untrack connection if it's closed in pool.release
1 parent b586e3c commit b5b1c99

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

asyncpg/pool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ async def acquire(self, *, timeout=None):
120120

121121
async def release(self, connection):
122122
self._check_init()
123-
if connection._protocol.queries_count >= self._max_queries:
123+
if connection.is_closed():
124+
self._con_count -= 1
125+
self._connections.remove(connection)
126+
elif connection._protocol.queries_count >= self._max_queries:
124127
self._con_count -= 1
125128
self._connections.remove(connection)
126129
await connection.close()

tests/test_pool.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,19 @@ async def test_pool_03(self):
6161

6262
pool.terminate()
6363
del con
64+
65+
async def test_pool_04(self):
66+
addr = self.cluster.get_connection_addr()
67+
pool = await asyncpg.create_pool(host=addr[0], port=addr[1],
68+
database='postgres',
69+
loop=self.loop, min_size=1,
70+
max_size=1)
71+
72+
con = await pool.acquire(timeout=0.1)
73+
con.terminate()
74+
await pool.release(con)
75+
76+
con = await pool.acquire(timeout=0.1)
77+
self.assertEqual(await con.fetchval('SELECT 1'), 1)
78+
79+
await pool.close()

0 commit comments

Comments
 (0)