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

ConnectionPool.get_connection returns connection twice

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.6
    • 1.1.7
    • Connection Pooling
    • 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
      

      Attachments

        Activity

          People

            georg Georg Richter
            gmech G.Mech
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.