Atomikos Forum |
|
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(); } |