You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/12/10 01:23:39 UTC

svn commit: r1549718 - /manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java

Author: kwright
Date: Tue Dec 10 00:23:38 2013
New Revision: 1549718

URL: http://svn.apache.org/r1549718
Log:
Try not to leave the world in a messed up state when abandoning connections; this causes any multiple-agent tests to fail once in a while.

Modified:
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1549718&r1=1549717&r2=1549718&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java (original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java Tue Dec 10 00:23:38 2013
@@ -688,13 +688,26 @@ public abstract class Database
       }
     }
 
-    public Throwable getException()
-    {
-      return exception;
-    }
-
-    public IResultSet getResponse()
+    public IResultSet finishUp()
+      throws ManifoldCFException, InterruptedException
     {
+      join();
+      Throwable thr = exception;
+      if (thr != null)
+      {
+        if (thr instanceof ManifoldCFException)
+        {
+          // Nest the exceptions so there is a hope we actually see the context, while preserving the kind of error it is
+          ManifoldCFException me = (ManifoldCFException)thr;
+          throw new ManifoldCFException("Database exception: "+me.getMessage(),me.getCause(),me.getErrorCode());
+        }
+        else if (thr instanceof Error)
+          throw (Error)thr;
+        else if (thr instanceof RuntimeException)
+          throw (RuntimeException)thr;
+        else
+          throw new RuntimeException("Unknown exception: "+thr.getClass().getName()+": "+thr.getMessage(),thr);
+      }
       return rval;
     }
   }
@@ -712,24 +725,22 @@ public abstract class Database
     try
     {
       t.start();
-      t.join();
-      Throwable thr = t.getException();
-      if (thr != null)
-      {
-        if (thr instanceof ManifoldCFException)
-        {
-          // Nest the exceptions so there is a hope we actually see the context, while preserving the kind of error it is
-          ManifoldCFException me = (ManifoldCFException)thr;
-          throw new ManifoldCFException("Database exception: "+me.getMessage(),me.getCause(),me.getErrorCode());
-        }
-        else
-          throw (Error)thr;
-      }
-      return t.getResponse();
+      return t.finishUp();
     }
     catch (InterruptedException e)
     {
+      // Try to kill the background thread - but we can't wait for it...
       t.interrupt();
+      // VERY IMPORTANT: Try to close the connection, so nothing is left dangling.  The connection will be abandoned anyhow.
+      try
+      {
+        if (!connection.getAutoCommit())
+          connection.rollback();
+        connection.close();
+      }
+      catch (Exception e2)
+      {
+      }
       // We need the caller to abandon any connections left around, so rethrow in a way that forces them to process the event properly.
       throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.INTERRUPTED);
     }