Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
1.1.6
-
None
-
Win10 21H2, mariadb Server 10.6.11 (docker)
-
3.10.4
Description
Steps to reproduce
1. Setup server with short WAIT_TIMEOUT:
docker run -e MARIADB_ROOT_PASSWORD="<put_password_here>" -p 3306:3306 mariadb:10.6.11 --wait-timeout=10
2. Create a connection pool (see attached file)
3. Wait a little longer than WAIT_TIMEOUT
4. Get pool_size connections without closing them
Expected outcome
Each connection returned by get_connection is unique.
Actual outcome
One connection is returned twice
Suspected cause
get_connections deletes the connection to be returned from _connections_free and adds it to _connections_used
for i in range(0, len(self._connections_free)): |
conn = self._connections_free[i] |
# abbreviated: call _replace_connection if necessary; |
conn._used += 1 |
self._connections_used.append(conn) |
del self._connections_free[i] |
If _replace_connection is called, it adds the new connection at the end of the list, so
del self._connections_free[i] |
deletes a different connection.
Possible fix
See attached patch.
diff --git a/mariadb/connectionpool.py b/mariadb/connectionpool.py
|
index 882ff69..b17c984 100644
|
--- a/mariadb/connectionpool.py
|
+++ b/mariadb/connectionpool.py
|
@@ -218,7 +218,8 @@ class ConnectionPool(object):
|
|
conn._used += 1
|
self._connections_used.append(conn)
|
- del self._connections_free[i]
|
+ x = self._connections_free.index(conn)
|
+ del self._connections_free[x]
|
return conn
|
|
return None
|