avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1296492 - in /avro/trunk: CHANGES.txt lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java
Date Fri, 02 Mar 2012 22:09:30 GMT
Author: cutting
Date: Fri Mar  2 22:09:30 2012
New Revision: 1296492

URL: http://svn.apache.org/viewvc?rev=1296492&view=rev
Log:
AVRO-1027. Java: Fix deadlock in NettyTransceiver.  Contributed by jbaldassari.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1296492&r1=1296491&r2=1296492&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Mar  2 22:09:30 2012
@@ -32,6 +32,9 @@ Avro 1.6.3 (unreleased)
     AVRO-1041. Java: Fix Utf8 to reuse array in more cases.
     (Dave Irving via cutting)
 
+    AVRO-1027. Java: Fix deadlock in NettyTransceiver.
+    (jbaldassari via cutting)
+
 Avro 1.6.2 (13 February 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java?rev=1296492&r1=1296491&r2=1296492&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java (original)
+++ avro/trunk/lang/java/ipc/src/main/java/org/apache/avro/ipc/NettyTransceiver.java Fri Mar
 2 22:09:30 2012
@@ -28,7 +28,6 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -81,7 +80,7 @@ public class NettyTransceiver extends Tr
    * Read lock must be acquired whenever using non-final state.
    * Write lock must be acquired whenever modifying state.
    */
-  private final ReadWriteLock stateLock = new ReentrantReadWriteLock();
+  private final ReentrantReadWriteLock stateLock = new ReentrantReadWriteLock();
   private Channel channel;       // Synchronized on stateLock
   private Protocol remote;       // Synchronized on stateLock
 
@@ -280,6 +279,10 @@ public class NettyTransceiver extends Tr
       Throwable cause) {
     Channel channelToClose = null;
     Map<Integer, Callback<List<ByteBuffer>>> requestsToCancel = null;
+    boolean stateReadLockHeld = stateLock.getReadHoldCount() != 0;
+    if (stateReadLockHeld) {
+      stateLock.readLock().unlock();
+    }
     stateLock.writeLock().lock();
     try {
       if (channel != null) {
@@ -301,6 +304,9 @@ public class NettyTransceiver extends Tr
         }
       }
     } finally {
+      if (stateReadLockHeld) {
+        stateLock.readLock().lock();
+      }
       stateLock.writeLock().unlock();
     }
     



Mime
View raw message