Bug 445 : rollback in a case of database connection closed, but not close connection resulting in connection pool leaks
Priority 
High
Reported Version 
 
Logged By 
Abbas
Status 
Fixed
Fixed Version 
3.3.2
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
21/08/2013
Updated 
21/08/2013
Type 
Bug
 
Attachments 
No attachments

In JdbcTransaction, rollback should always close a connection even if the rollback results in an exception.

Current Code:

/**
* Rollback the transaction.
* If there is a throwable it is logged as the cause in the transaction log.
*/
public void rollback(Throwable cause) throws PersistenceException {
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}
try {
connection.rollback();

// these will not throw an exception
deactivate();
notifyRollback(cause);

} catch (Exception ex) {
throw new PersistenceException(ex);
}
}

Proposed Code:

/**
* Rollback the transaction. If there is a throwable it is logged as the cause
* in the transaction log.
*/
public void rollback(Throwable cause) throws PersistenceException {
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}

PersistenceException e = null;

try {
connection.rollback();
} catch (Exception ex) {
e = new PersistenceException(ex);
}

// these will not throw an exception
deactivate();

if (e == null)
notifyRollback(cause);

if (e != null)
throw e;
}

 
woResponse

Upload a file