Struts connection pool implemented in GenericDataSource.java does not handle
stale connections.
Stale connections are connections having been closed by the database. This
could be due to no activity timeout (such as wait_timeout in mysql) or the
database was down and up again. Currently when returning a pool connection to
a caller in getConnection(), Struts does not check if the real database
connection of that pool connection has been closed or not.
Below is my patch for this problem in the GenericDataSource.java, revision 1.5
-
-
- GenericDataSource.java.r1.5 Wed May 23 17:44:12 2001
- GenericDataSource.java.r1.5fixed Wed May 23 17:31:07 2001
***************
- 402,414 ****
-
// Return an existing connection from the pool if there is one
synchronized (connections) {
! if (!connections.isEmpty())
}
— 402,425 ----
// Return an existing connection from the pool if there is one
synchronized (connections) {
! while (!connections.isEmpty()) {
GenericConnection connection = (GenericConnection)
connections.removeFirst();
+ // Checking for stale connection. Stale connections are
connections
+ // closed by the database. This could be due to no
activity
+ // timeout (such as mysql wait_timeout) or the database
was down
+ // and up again.
+ if (connection.getConnection().isClosed())
+
+ else
{ // unclose the connection's wrapper + useCount++; connection.setClosed(false); return(connection); ! } }
}