Details
- 
    Bug 
- 
    Status: Closed (View Workflow)
- 
    Critical 
- 
    Resolution: Fixed
- 
    1.1.13
- 
    None
- 
    win10
- 
        3.9.13
Description
When an error happens while initializing ConnectionPool (for me it was OperationalError: Too many connections), the error handling code does not close all open connections and raises an IndexError
Steps to Reproduce
not tested
- change ConnectionPool._init_  index a18d81a..cf59d82 100644--- a/mariadb/connectionpool.py+++ b/mariadb/connectionpool.py@@ -108,6 +108,8 @@ class ConnectionPool(object):# fill connection poolfor i in range(0, self._pool_args["size"]):try:+ if i == 5:+ raise mariadb.Error("ONLY TESTING")connection = mariadb.Connection(**self._conn_args)except mariadb.Error:# if an error occurred, close all connections 
- Initialize ConnectionPool {{c = ConnectionPool(<parameters>)}
Expected result
- Connections 0…4 get closed
- mariadb.Error raised
Actual result
- Only every second connection closed.
- Raises IndexError: list index out of range
Suggested Fix
Not tested.
Delete connections in reverse order:
| diff --git a/mariadb/connectionpool.py b/mariadb/connectionpool.py | 
| index a18d81a..1a69cba 100644 | 
| --- a/mariadb/connectionpool.py | 
| +++ b/mariadb/connectionpool.py | 
| @@ -112,7 +112,7 @@ class ConnectionPool(object): | 
|                      except mariadb.Error: | 
|                          # if an error occurred, close all connections | 
|                          # and raise exception | 
| -                        for j in range(0, len(self._connections_free)): | 
| +                        for j in reversed(range(len(self._connections_free))): | 
|                              try: | 
|                                  self._connections_free[j].close() | 
| except mariadb.Error: |