Skip to content

Commit 658cc00

Browse files
committed
Fix for CONPY-256:
Fix indexing when moving a free connection to used connections to avoid returning the same connection twice. Kudos and thanks to G.Mech for reporting this bug and providing the fix.
1 parent 494d951 commit 658cc00

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mariadb/connectionpool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def get_connection(self):
218218

219219
conn._used += 1
220220
self._connections_used.append(conn)
221-
del self._connections_free[i]
221+
idx = self._connections_free.index(conn)
222+
del self._connections_free[idx]
222223
return conn
223224

224225
raise mariadb.PoolError("No connection available")

testing/test/integration/test_pooling.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,18 @@ def test_pool_add(self):
356356
pool.close()
357357
self.assertEqual(mariadb._CONNECTION_POOLS, {})
358358

359+
def test_conpy256(self):
360+
size = 10
361+
connections = []
362+
default_conf = conf()
363+
pool = mariadb.ConnectionPool(pool_name="test_conpy256",
364+
pool_size=size, **default_conf)
365+
for i in range(size):
366+
c= pool.get_connection()
367+
self.assertNotEqual(c in connections, True)
368+
connections.append(c)
369+
370+
pool.close()
359371

360372
if __name__ == '__main__':
361373
unittest.main()

0 commit comments

Comments
 (0)