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

Exception observed during the recycle phase of a connection pool

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 1.1.14
    • None
    • Connection Pooling
    • None
    • Ubuntu 24.04LTS
    • 3.14.5

    Description

      Hi Support,

      I'm observing an exception during the close() invocation of a connection of a pool that uses a recycle logic, that is that recycles connections every N seconds. The exception says that:

      [...]/lib/python3.14/site-packages/mariadb/connections.py", line 119, in close
      if self._Connection__pool:
      ^^^^^^^^^^^^^^^^^^^^^^
      AttributeError: 'Connection' object has no attribute '_Connection__pool'
      

      The exception doesn't depend by the value of N.

      Investigating this issue it's possible to observe that, when the close() is invoked during a recycle phase, the Connection has no attributes at all. Drilling down further, it could be observed that the Connection is in effects no more active, that is the object is no more valid. In facts, even skipping the call to self.Connection_pool._close_connection(self), the invocation of super().close() ends with a mariadb.InterfaceError exception.

      Finally, I also noted that the Connection_pool attribute is not defined but __pool is, maybe a typo?

      The exception is non-blocking, at least in my use case, just noisy due to the trace. I temporarely fixed it as follows:

      diff -Naru '--exclude=*.pyc' '--exclude=*.js' myapp.vanilla/lib/python3.14/site-packages/mariadb/connections.py myapp/lib/python3.14/site-packages/mariadb/connections.py
      --- myapp.vanilla/lib/python3.14/site-packages/mariadb/connections.py	2026-06-09 11:10:37.823464806 +0200
      +++ myapp/lib/python3.14/site-packages/mariadb/connections.py	2026-06-28 11:30:17.743937249 +0200
      @@ -54,7 +54,7 @@
               self._used = 0
               self._last_executed_statement = None
               self._socket = None
      -        self.__pool = None
      +        self._Connection__pool = None
               self.__last_used = 0
               self.tpc_state = TPC_STATE.NONE
               self._xid = None
      @@ -116,10 +116,17 @@
       
           def close(self):
               self._check_closed()
      -        if self._Connection__pool:
      +        if hasattr(self, "_Connection__pool") and self._Connection__pool:
                   self._Connection__pool._close_connection(self)
               else:
      -            super().close()
      +            try:
      +                super().close()
      +            except (mariadb.InterfaceError,) as e:
      +                # Connection already closed
      +                # print(f"Warning: MariaDB Connection.close() invocation failed with non-blocking exception: {e}")
      +                pass
      +            except Exception as e:
      +                raise(e)
       
           def __enter__(self):
               self._check_closed()
      
      

      The commented print was used just for tracing purposes.

      Attachments

        Activity

          People

            georg Georg Richter
            mottimo Max
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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