Author: kwright
Date: Tue Jan 22 18:47:21 2013
New Revision: 1437093
URL: http://svn.apache.org/viewvc?rev=1437093&view=rev
Log:
Prevent connection errors from leaking connection handles. Fix for
CONNECTORS-620.
Modified:
manifoldcf/trunk/CHANGES.txt
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnection.java
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnectionFactory.java
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnector.java
Modified: manifoldcf/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1437093&r1=1437092&r2=1437093&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Tue Jan 22 18:47:21 2013
@@ -8,6 +8,10 @@ CONNECTORS-617: Simple report NPE under
======================= Release 1.1 =====================
+CONNECTORS-620: It was possible for the JDBC Connector to leak
+JDBC connections under some error conditions.
+(Anthony Leonard, Karl Wright)
+
CONNECTORS-619: Include slf4j jars in multiprocess agents classpath.
This was causing Solrj to not work on multiprocess deployments.
(Erlend Garåsen, Karl Wright)
Modified:
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnection.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnection.java?rev=1437093&r1=1437092&r2=1437093&view=diff
==============================================================================
---
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnection.java
(original)
+++
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnection.java
Tue Jan 22 18:47:21 2013
@@ -863,45 +863,79 @@ public class JDBCConnection
throws ManifoldCFException, ServiceInterruption
{
ManifoldCFException rval = null;
+ Error error = null;
+ RuntimeException rtException = null;
if (rs != null)
{
try
{
closeResultset(rs);
- rs = null;
}
catch (ManifoldCFException e)
{
if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
rval = e;
}
+ catch (Error e)
+ {
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
+ finally
+ {
+ rs = null;
+ }
}
if (stmt != null)
{
try
{
closeStmt(stmt);
- stmt = null;
}
catch (ManifoldCFException e)
{
if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
rval = e;
}
+ catch (Error e)
+ {
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
+ finally
+ {
+ stmt = null;
+ }
}
if (connection != null)
{
try
{
JDBCConnectionFactory.releaseConnection(connection);
- connection = null;
}
- catch (ManifoldCFException e)
+ catch (Error e)
{
- if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
- rval = e;
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
+ finally
+ {
+ connection = null;
}
}
+ if (error != null)
+ throw error;
+ if (rtException != null)
+ throw rtException;
if (rval != null)
throw rval;
}
@@ -947,15 +981,17 @@ public class JDBCConnection
{
closeResultset(rs);
}
- catch (ServiceInterruption e2)
- {
- }
catch (ManifoldCFException e2)
{
if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
this.exception = e2;
// Ignore
}
+ catch (Throwable e2)
+ {
+ // We already have an exception to report.
+ // Eat any other exceptions from closing
+ }
finally
{
rs = null;
@@ -967,15 +1003,17 @@ public class JDBCConnection
{
closeStmt(stmt);
}
- catch (ServiceInterruption e2)
- {
- }
catch (ManifoldCFException e2)
{
if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
this.exception = e2;
// Ignore
}
+ catch (Throwable e2)
+ {
+ // We already have an exception to report.
+ // Eat any other exceptions from closing statements
+ }
finally
{
stmt = null;
@@ -983,23 +1021,8 @@ public class JDBCConnection
}
if (connection != null)
{
- try
- {
- JDBCConnectionFactory.releaseConnection(connection);
- }
- catch (ServiceInterruption e2)
- {
- }
- catch (ManifoldCFException e2)
- {
- if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
- this.exception = e2;
- // Otherwise, ignore
- }
- finally
- {
- connection = null;
- }
+ JDBCConnectionFactory.releaseConnection(connection);
+ connection = null;
}
}
}
@@ -1108,6 +1131,8 @@ public class JDBCConnection
throws ManifoldCFException, ServiceInterruption
{
ManifoldCFException rval = null;
+ Error error = null;
+ RuntimeException rtException = null;
if (rs != null)
{
try
@@ -1122,6 +1147,14 @@ public class JDBCConnection
if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
rval = e;
}
+ catch (Error e)
+ {
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
finally
{
rs = null;
@@ -1141,6 +1174,14 @@ public class JDBCConnection
if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
rval = e;
}
+ catch (Error e)
+ {
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
finally
{
ps = null;
@@ -1152,13 +1193,13 @@ public class JDBCConnection
{
JDBCConnectionFactory.releaseConnection(connection);
}
- catch (ServiceInterruption e)
+ catch (Error e)
{
+ error = e;
}
- catch (ManifoldCFException e)
+ catch (RuntimeException e)
{
- if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
- rval = e;
+ rtException = e;
}
finally
{
@@ -1170,14 +1211,29 @@ public class JDBCConnection
try
{
cleanupParameters(params);
- params = null;
}
catch (ManifoldCFException e)
{
if (rval == null || e.getErrorCode() ==
ManifoldCFException.INTERRUPTED)
rval = e;
}
+ catch (Error e)
+ {
+ error = e;
+ }
+ catch (RuntimeException e)
+ {
+ rtException = e;
+ }
+ finally
+ {
+ params = null;
+ }
}
+ if (error != null)
+ throw error;
+ if (rtException != null)
+ throw rtException;
if (rval != null)
throw rval;
@@ -1225,14 +1281,14 @@ public class JDBCConnection
{
closeResultset(rs);
}
- catch (ServiceInterruption e2)
- {
- }
catch (ManifoldCFException e2)
{
if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
this.exception = e2;
}
+ catch (Throwable e2)
+ {
+ }
finally
{
rs = null;
@@ -1244,14 +1300,14 @@ public class JDBCConnection
{
closePS(ps);
}
- catch (ServiceInterruption e2)
- {
- }
catch (ManifoldCFException e2)
{
if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
this.exception = e2;
}
+ catch (Throwable e2)
+ {
+ }
finally
{
ps = null;
@@ -1259,22 +1315,8 @@ public class JDBCConnection
}
if (connection != null)
{
- try
- {
- JDBCConnectionFactory.releaseConnection(connection);
- }
- catch (ServiceInterruption e2)
- {
- }
- catch (ManifoldCFException e2)
- {
- if (e2.getErrorCode() == ManifoldCFException.INTERRUPTED)
- this.exception = e2;
- }
- finally
- {
- connection = null;
- }
+ JDBCConnectionFactory.releaseConnection(connection);
+ connection = null;
}
}
}
Modified:
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnectionFactory.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnectionFactory.java?rev=1437093&r1=1437092&r2=1437093&view=diff
==============================================================================
---
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnectionFactory.java
(original)
+++
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnectionFactory.java
Tue Jan 22 18:47:21 2013
@@ -173,7 +173,6 @@ public class JDBCConnectionFactory
}
public static void releaseConnection(WrappedConnection c)
- throws ManifoldCFException, ServiceInterruption
{
c.release();
}
Modified:
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnector.java
URL:
http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnector.java?rev=1437093&r1=1437092&r2=1437093&view=diff
==============================================================================
---
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnector.java
(original)
+++
manifoldcf/trunk/connectors/jdbc/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jdbc/JDBCConnector.java
Tue Jan 22 18:47:21 2013
@@ -241,6 +241,8 @@ public class JDBCConnector extends org.a
String queryText = sb.toString();
long startQueryTime = System.currentTimeMillis();
+ // Contract for IDynamicResultset indicates that if successfully obtained,
it MUST
+ // be closed.
try
{
idSet = connection.executeUncachedQuery(queryText,paramList,-1);
@@ -357,6 +359,8 @@ public class JDBCConnector extends org.a
IDynamicResultSet result;
String queryText = sb.toString();
long startTime = System.currentTimeMillis();
+ // Get a dynamic resultset. Contract for dynamic resultset is that if
+ // one is returned, it MUST be closed, or a connection will leak.
try
{
result = connection.executeUncachedQuery(queryText,paramList,-1);
@@ -368,11 +372,11 @@ public class JDBCConnector extends org.a
createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
throw e;
}
- // If success, record that too.
- activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY,
null,
- createQueryString(queryText,paramList), "OK", null, null);
try
{
+ // If success, record that too.
+ activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY,
null,
+ createQueryString(queryText,paramList), "OK", null, null);
// Now, go through resultset
while (true)
{
@@ -471,6 +475,8 @@ public class JDBCConnector extends org.a
IDynamicResultSet result;
String queryText = sb.toString();
long startTime = System.currentTimeMillis();
+ // Get a dynamic resultset. Contract for dynamic resultset is that if
+ // one is returned, it MUST be closed, or a connection will leak.
try
{
result = connection.executeUncachedQuery(queryText,paramList,-1);
@@ -482,12 +488,12 @@ public class JDBCConnector extends org.a
createQueryString(queryText,paramList), "ERROR", e.getMessage(), null);
throw e;
}
- // If success, record that too.
- activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY,
null,
- createQueryString(queryText,paramList), "OK", null, null);
-
try
{
+ // If success, record that too.
+ activities.recordActivity(new Long(startTime), ACTIVITY_EXTERNAL_QUERY,
null,
+ createQueryString(queryText,paramList), "OK", null, null);
+
while (true)
{
IResultRow row = result.getNextRow();