Project: Tomcat
Bug 49831 Issue with closing XAConnections on MSSQL
Reported: 2010-08-26 11:08:08 | Status: resolved fixed

When using XAConnections with MSSQL it has been noticed that the physical connections are not being closed when DataSourceProxy.close(boolean all) is called. This method invokes org.apache.tomcat.jdbc.pool.PooledConnection.disconnent() which calls connection.close(). However, when used with SQLServer, the connection attribute is a proxy object (type com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolProxy) which wraps the physical connection (of type com.microsoft.sqlserver.jdbc.SQLServerConnection). Calling close() on the proxy object only notifies the pool manager that the Connection is released back to the pool; it does not close the underlying physical connection. This is what the PooledConnection.disconnent() implementation currently reads: private void disconnect(boolean finalize) { if (isDiscarded()) { return; } setDiscarded(true); if (connection != null) { try { connection.close(); }catch (Exception ignore) { if (log.isDebugEnabled()) { log.debug("Unable to close underlying SQL connection",ignore); } } } connection = null; xaConnection = null; lastConnected = -1; if (finalize) parent.finalize(this); } If the logic was changed to the following, it would properly closed the XAConnection with the MSSQL. private void disconnect(boolean finalize) { if (isDiscarded()) { return; } setDiscarded(true); if (connection != null) { try { if (xaConnection != null) { xaConnection.close(); } else { connection.close(); } }catch (Exception ignore) { if (log.isDebugEnabled()) { log.debug("Unable to close underlying SQL connection",ignore); } } } connection = null; xaConnection = null; lastConnected = -1; if (finalize) parent.finalize(this); }

Files changed in fix:
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java