Atomikos Forum

Bug in connection pool reaping logic

Hi,

We have seen an issue where by connections have been reaped whilst in use for a very small period of time (often on milliseconds). This resuls in the database connection being closed and transactions rolling back.

The following code reproduces the problem:

// Set stuff up
TransactionManager txnManager = ...;
AtomikosDataSourceBean xaDataSource = ...;


// Set the reap timeout and maintaince period for the test
xaDataSource.setReapTimeout( 5 );
xaDataSource.setMaintenanceInterval( 1 );

logger.info("\n\nINIT COMPLETE\n\n");

Connection connection;
Statement statement;

// Transaction 1
System.out.println("\n\nSTARTING TRANSACTION 1\n\n");
txnManager.begin();

// Do stuff
connection = xaDataSource.getConnection();
statement = connection.createStatement();
System.out.println("RESULT 1 " + statement.execute("SELECT 1") );

statement.close();
connection.close();

txnManager.commit();
System.out.println("\n\nCOMMITED TRANSACTION 1\n\n");

// Sleep for 6 seconds - now the connection will be reaped
Thread.sleep( 6000 );

// Transaction 2
System.out.println("\n\nSTARTING TRANSACTION 2\n\n");
txnManager.begin();

// Do stuff
connection = xaDataSource.getConnection();

// The connection will be reaped - we need to wait 1 second
// for the maintaince thread to jump in
Thread.sleep( 1000 );

statement = connection.createStatement();

System.out.println("RESULT 2 " + statement.execute("SELECT 1") );


statement.close();
connection.close();

txnManager.commit();
System.out.println("\n\nCOMMITED TRANSACTION 2\n\n");


I think the bug is in ConnectionPool - where the reaping logic checks the connection was returned to the pool more than the reap period, not aquired more than the reap period (around line 190):

// THIS SHOULD BE xpc.getLastTimeAquired();
long lastTimeReleased = xpc.getLastTimeReleased();
boolean inUse = !xpc.isAvailable();
           
long now = System.currentTimeMillis();
if ( inUse && ( ( now - maxInUseTime * 1000 ) > lastTimeReleased ) ) {
  Configuration.logDebug ( this + ": connection in use for more than " + maxInUseTime + "s, reaping it: " + xpc );
  xpc.reap();
}
Tim Wright Send private email
Thursday, July 02, 2009
 
 
Thanks for the feedback, I have created an issue for the next release (TransactionsEssentials 3.5.7).
Guy Pardon Send private email
Monday, July 06, 2009
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics