瀏覽代碼

ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@886241 13f79535-47bb-0310-9956-ffa450edef68
Benjamin Reed 15 年之前
父節點
當前提交
154647fa5d
共有 2 個文件被更改,包括 44 次插入35 次删除
  1. 3 0
      CHANGES.txt
  2. 41 35
      src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

+ 3 - 0
CHANGES.txt

@@ -139,6 +139,9 @@ BUGFIXES:
   ZOOKEEPER-598. LearnerHandler is misspelt in the thread's constructor 
   (Henry Robinson via fpj)
 
+  ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk (take 2)
+  (breed)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

+ 41 - 35
src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

@@ -955,10 +955,12 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
         }
         jmxConnectionBean = null;
 
-        if (closed) {
-            return;
+        synchronized(this) {
+            if (closed) {
+                return;
+            }
+            closed = true;
         }
-        closed = true;
         synchronized (factory.ipMap)
         {
             Set<NIOServerCnxn> s = factory.ipMap.get(sock.socket().getInetAddress());
@@ -1038,42 +1040,46 @@ public class NIOServerCnxn implements Watcher, ServerCnxn {
      *      org.apache.jute.Record, java.lang.String)
      */
     synchronized public void sendResponse(ReplyHeader h, Record r, String tag) {
-        if (closed) {
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("send called on closed session 0x"
-                          + Long.toHexString(sessionId)
-                          + " with record " + r);
-            }
-            return;
-        }
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        // Make space for length
-        BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
         try {
-            baos.write(fourBytes);
-            bos.writeRecord(h, "header");
-            if (r != null) {
-                bos.writeRecord(r, tag);
+            if (closed) {
+                if (LOG.isTraceEnabled()) {
+                    LOG.trace("send called on closed session 0x"
+                              + Long.toHexString(sessionId)
+                              + " with record " + r);
+                }
+                return;
             }
-            baos.close();
-        } catch (IOException e) {
-            LOG.error("Error serializing response");
-        }
-        byte b[] = baos.toByteArray();
-        ByteBuffer bb = ByteBuffer.wrap(b);
-        bb.putInt(b.length - 4).rewind();
-        sendBuffer(bb);
-        if (h.getXid() > 0) {
-            synchronized (this.factory) {
-                outstandingRequests--;
-                // check throttling
-                if (zk.getInProcess() < factory.outstandingLimit
-                        || outstandingRequests < 1) {
-                    sk.selector().wakeup();
-                    enableRecv();
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            // Make space for length
+            BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos);
+            try {
+                baos.write(fourBytes);
+                bos.writeRecord(h, "header");
+                if (r != null) {
+                    bos.writeRecord(r, tag);
                 }
+                baos.close();
+            } catch (IOException e) {
+                LOG.error("Error serializing response");
             }
-        }
+            byte b[] = baos.toByteArray();
+            ByteBuffer bb = ByteBuffer.wrap(b);
+            bb.putInt(b.length - 4).rewind();
+            sendBuffer(bb);
+            if (h.getXid() > 0) {
+                synchronized (this.factory) {
+                    outstandingRequests--;
+                    // check throttling
+                    if (zk.getInProcess() < factory.outstandingLimit
+                            || outstandingRequests < 1) {
+                        sk.selector().wakeup();
+                        enableRecv();
+                    }
+                }
+            }
+         } catch(Exception e) {
+            LOG.error("Unexpected exception. Destruction averted.", e);
+         }
     }
 
     /*