Skip to content

JDBC Connection is not released due to incorrectly defined catch [SPR-10755] #15381

@spring-projects-issues

Description

@spring-projects-issues

Peter Szanto opened SPR-10755 and commented

DataSourceTransactionManager contains a bug when releasing the connection. According to the official recommendation, The problem here is that the code only releases the connection when an exception occurs, not when an Error. In our case when an OutOfMemoryError occurs we notice that the connections are not released. Here is the code snipped from doBegin()

try {

...
catch (Exception ex) {
	DataSourceUtils.releaseConnection(con, this.dataSource);
	throw new CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex);
}

The problem is that OOM can be recovered, but not releasing the connections cannot be recovered.

Not sure how much it is related, but when I see abandoned JDBC connections I also see these in the log file :

org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is java.sql.SQLException: Connection com.microsoft.sqlserver.jdbc.SQLServerConnection@266290d7 is closed.

Affects: 3.2.3

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions