-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Urs Keller opened SPR-5780 and commented
In TransactionAwareDataSourceProxy isClosed() is not specially handled, under some circumstances the call to this method will create a connection, which is then leaked, since callers are using isClosed() in a finally clause when releasing resources.
We experienced this problem with a connection pool when bounding the number of connections and under high load when the pool becomes exhausted. Under these circumstances the connections are leaking.
If we assume a pool with 1 connection and we are using TransactionAwareDataSourceProxy.
Thread 1) gets the connection and holds it.
Thread 2) tries to get a connection, but since 1) holds it it has a timeout.
We have a context switch to 1) which releases the connection.
We have a context switch to 2). Since it holds a TransactionAwareDataSourceProxy Connection, it will still try to close it. In particular the isCosed method is called and since the target connection is null a new connection is created, which is then leaked.
I tentatively fixed this problem by handling the isClosed when target is null. This passes the tests with which I could reproduce the problem. I'm not sure if there are unwanted side effects, though.
Patch below:
1. Eclipse Workspace Patch 1.0
#P spring-2-5-6-SEC01
Index: src/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
--- src/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java (revision 17121)
+++ src/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java (working copy)
@@ -201,6 +201,12 @@
this.closed = true;
return null;
}
+
// prevent isClosed from opening new connections.
// since isClosed is usually called in finally blocks
// this would cause connections to leak.
else if (method.getName().equals("isClosed") && this.target==null) {
return true;
}
if (this.target == null) {
if (this.closed) {
Affects: 2.5.6
Referenced from: commits d46c1f6
1 votes, 5 watchers