Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1291

ConnectionPoolDataSource incompatibility / Connection leaks due to internal ConnectionEventListener in MariaDB Connector/J 3.5.x

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Blocker
    • Resolution: Fixed
    • 3.5.3, 3.5.4, 3.5.2, 3.5.5, 3.5.6
    • 3.5.7
    • pooling
    • None
    • MariaDB Connector/J Version: 3.5.2+ (confirmed for 3.5.6)
      Java Version: (JDK 8, 11)
      Database Server: (11.2.2)
      Connection Pool Implementation: Custom (but issue affects libraries using `ConnectionPoolDataSource` interface)

    Description

      Summary
      Since upgrading to MariaDB Connector/J 3.5.x, our custom JDBC connection pool implementation and usage of ConnectionPoolDataSource are experiencing issues where connections are physically closed by the driver as soon as the application closes the logical (pooled) connection. This causes connection leaks, forces unnecessary connection recreation, and breaks compatibility with common pool implementations.

      Steps to Reproduce

      1. Use MariaDbDataSource as a ConnectionPoolDataSource.
      2. Obtain a PooledConnection via getPooledConnection().
      3. Add a custom ConnectionEventListener to the pooled connection to manage the resource when connectionClosed() is called.
      4. Close the logical connection (e.g., client calls Connection.close()).
      5. Observe that the underlying physical connection is closed by the driver, not returned to the pool.

      Expected Behavior
      When the application closes the logical pooled connection, it should only return the connection to the pool for potential reuse. The physical database connection should NOT be closed unless requested by the pool manager. The driver should not forcibly close physical connections.

      Actual Behavior
      Since [commit 1ce5982...](https://github.com/mariadb-corporation/mariadb-connector-j/commit/1ce598284e293a79a082e4a06291ec3184e8dffb), the driver always registers an internal ConnectionEventListener that calls realClose() (closes the physical connection) as soon as the pooled connection is closed, regardless of pool management. This breaks the pooling layer and causes connection leaks.

      Impact

      • JDBC pools cannot reuse connections; every returned connection is dead.
      • Frequent TCP/DB connection churn, reduced performance, increased errors.
      • Nonstandard behavior compared to other JDBC drivers (e.g., Oracle, PostgreSQL, MySQL standard drivers).
      • Application resource leaks or exceptions on reborrowing pooled connections.

      Steps to Fix / Proposal

      • Make the internal ConnectionEventListener registration optional when the data source is used as a ConnectionPoolDataSource.
      • Provide a configuration property to disable the driver's forced physical close on logical connection close.
      • Match the default behavior of older driver releases (3.4.2 and before), where pool manager controlled physical connection lifecycle.

      References

      Workaround
      Downgrading to 3.4.2 or earlier is the only current workaround. Would prefer a long-term fix in the official driver.

      Additional Information

      • Please find sample code attached for issue reproduction.
      • Happy to provide logs, debug output, or collaborate on patch review.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            mugdha.datar Mugdha Datar
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.