Author: breed
Date: Wed Dec  2 18:36:24 2009
New Revision: 886241

URL: http://svn.apache.org/viewvc?rev=886241&view=rev
Log:
ZOOKEEPER-597. ASyncHammerTest is failing intermittently on hudson trunk

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=886241&r1=886240&r2=886241&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Wed Dec  2 18:36:24 2009
@@ -139,6 +139,9 @@
   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)

Modified: 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java?rev=886241&r1=886240&r2=886241&view=diff
==============================================================================
--- 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
 (original)
+++ 
hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
 Wed Dec  2 18:36:24 2009
@@ -955,10 +955,12 @@
         }
         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 @@
      *      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);
+         }
     }
 
     /*


Reply via email to