db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1514026 - in /db/derby/code/branches/10.8: ./ java/client/org/apache/derby/client/am/LogicalConnection.java
Date Wed, 14 Aug 2013 20:24:07 GMT
Author: kmarsden
Date: Wed Aug 14 20:24:07 2013
New Revision: 1514026

URL: http://svn.apache.org/r1514026
Log:
DERBY-5560 Java deadlock between LogicalConnection40 and ClientXAConnection40

Patch contributed by Brett Bergquist


Modified:
    db/derby/code/branches/10.8/   (props changed)
    db/derby/code/branches/10.8/java/client/org/apache/derby/client/am/LogicalConnection.java

Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
  Merged /db/derby/code/trunk:r1513218

Modified: db/derby/code/branches/10.8/java/client/org/apache/derby/client/am/LogicalConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/client/org/apache/derby/client/am/LogicalConnection.java?rev=1514026&r1=1514025&r2=1514026&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/client/org/apache/derby/client/am/LogicalConnection.java
(original)
+++ db/derby/code/branches/10.8/java/client/org/apache/derby/client/am/LogicalConnection.java
Wed Aug 14 20:24:07 2013
@@ -76,9 +76,14 @@ public class LogicalConnection implement
     // ------------------------ logical connection close -------------------------
     // All methods are simply forwarded to the physical connection, except for close() and
isClosed().
 
-    synchronized public void close() throws SQLException {
-        try
-        {
+    public void close() throws SQLException {
+        // The pooledConnection owns this LogicalConnection.  To ensure that
+        //  there is no deadlock when calling back into the pooledConnection_.recycleConnection
+        //  below, we first synchronize on the pooledConnection and then on this
+        //  LogicalConnection
+        synchronized (pooledConnection_) {
+            synchronized (this) {
+                try {
             // we also need to loop thru all the logicalStatements and close them
             if (physicalConnection_ == null) {
                 return;
@@ -89,7 +94,7 @@ public class LogicalConnection implement
 
             if (physicalConnection_.isClosed()) // connection is closed or has become stale
             {
-                pooledConnection_.informListeners(new SqlException(null, 
+                        pooledConnection_.informListeners(new SqlException(null,
                     new ClientMessageId(
                         SQLState.PHYSICAL_CONNECTION_ALREADY_CLOSED)));
             } else {
@@ -102,12 +107,12 @@ public class LogicalConnection implement
             }
             physicalConnection_ = null;
             pooledConnection_.nullLogicalConnection();
-        }
-        catch ( SqlException se )
-        {
+                } catch (SqlException se) {
             throw se.getSQLException();
         }
     }
+        }
+    }
 
     synchronized public void closeWithoutRecyclingToPool() throws SqlException {
         if (physicalConnection_ == null) {



Mime
View raw message