2

Where "ds" is a BoneCPDataSource initialized as follows:

    final BoneCPDataSource ds = new BoneCPDataSource();
    ds.setJdbcUrl("...");
    ds.setUser("...");
    ds.setPassword("...");
    ds.setCloseConnectionWatch(true);
    ds.setCloseConnectionWatchTimeout(1, TimeUnit.MINUTES);

Here is how I'm using it throughout my code:

try (Connection c = ds.getConnection()) {
    // do stuff with c, this takes 10 seconds at most
c.commit();
} catch (final Exception e) {
    logger.error("Report error", e);
}

But I'm seeing these:

WARNING: BoneCP detected an unclosed connection and will now attempt to close it for you. You should be closing this connection in your application - enable connectionWatch for additional debugging assistance. Mar 23, 2012 9:55:17 AM com.jolbox.bonecp.ConnectionPartition$1 finalizeReferent

It seems that the connection's finalizer is being called without the connection being closed - but how could this be? Doesn't the try-with-resource guarantee that the connection gets closed?

Then after this I start getting these errors:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.

Is there some way to get boneCP to show me a stacktrace where these finalized unclosed exceptions are being created? Can anyone suggest what the problem might be?

sanity
  • 35,347
  • 40
  • 135
  • 226

2 Answers2

1

Contrary to what was expected, the bug still appears in v0.8.0-RELEASE. Given this thread, the BoneCP author has built a 0.8.1-SNAPSHOT but it did not totally fix the problem.

It seems that many config settings may help, in particular setting

db.default.maxConnectionAge=0

Moreover, someone suggested that the error might come from the connection tracking mechanism in BoneCP and recommended to disable it by setting disableConnectionTracking=true in the code execution, if the connection management was performed by a framework like Spring.

In my case, I am using Play Framework 2.1.4, and mySQL (deployed on Heroku with ClearDB). I wrote the following code in the Global.scala file:

  override def onStart(app: Application) {
    play.api.db.DB.getDataSource() match {
      case ds: com.jolbox.bonecp.BoneCPDataSource => {
        ds.setDisableConnectionTracking(true)
      }
    }
  }

In addition to this, I also use the following DB configuration settings:

db.default.partitionCount=1
db.default.maxConnectionsPerPartition=7
db.default.minConnectionsPerPartition=7
db.default.acquireIncrement=1
db.default.acquireRetryAttempts=1
db.default.acquireRetryDelay=5 seconds
db.default.connectionTimeout=30 seconds
db.default.idleMaxAge=1 minutes
db.default.idleConnectionTestPeriod=30 seconds
db.default.connectionTestStatement="SELECT 1"
db.default.maxConnectionAge=0
db.default.autoReconnect=true
db.default.disableConnectionTracking=true

This seems to work out for now, but I cannot guarantee the problem was completely solved.

Hope this helps

teemoo
  • 881
  • 10
  • 16
0

This bug is supposedly fixed in v0.8.0-beta1

wwadge
  • 3,506
  • 1
  • 19
  • 28