Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-321

Exception handler in ConnectionPool.__init__ does not close all open connections and raises IndexError

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 1.1.13
    • 1.1.14
    • Connection Pooling
    • 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

      1. change ConnectionPool._init_

        index a18d81a..cf59d82 100644
        --- a/mariadb/connectionpool.py
        +++ b/mariadb/connectionpool.py
        @@ -108,6 +108,8 @@ class ConnectionPool(object):
                         # fill connection pool
                         for 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
        

      2. 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:
      

      Attachments

        Activity

          People

            georg Georg Richter
            gmech G.Mech
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.