Selaa lähdekoodia

ZOOKEEPER-1702. ZooKeeper client may write operation packets before receiving successful response to connection request, can cause TCP RST (Chris Nauroth via phunt)

git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1498732 13f79535-47bb-0310-9956-ffa450edef68
Patrick D. Hunt 12 vuotta sitten
vanhempi
commit
b40bb0b462
2 muutettua tiedostoa jossa 15 lisäystä ja 0 poistoa
  1. 4 0
      CHANGES.txt
  2. 11 0
      src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java

+ 4 - 0
CHANGES.txt

@@ -360,6 +360,10 @@ BUGFIXES:
   
   ZOOKEEPER-1663. scripts don't work when path contains spaces (Amichai Rothman via camille)
 
+  ZOOKEEPER-1702. ZooKeeper client may write operation packets before
+  receiving successful response to connection request, can cause TCP
+  RST (Chris Nauroth via phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

+ 11 - 0
src/java/main/org/apache/zookeeper/ClientCnxnSocketNIO.java

@@ -139,6 +139,17 @@ public class ClientCnxnSocketNIO extends ClientCnxnSocket {
                     // to attempt SASL authentication), or in either doIO() or
                     // in doTransport() if not.
                     disableWrite();
+                } else if (!initialized && p != null && !p.bb.hasRemaining()) {
+                    // On initial connection, write the complete connect request
+                    // packet, but then disable further writes until after
+                    // receiving a successful connection response.  If the
+                    // session is expired, then the server sends the expiration
+                    // response and immediately closes its end of the socket.  If
+                    // the client is simultaneously writing on its end, then the
+                    // TCP stack may choose to abort with RST, in which case the
+                    // client would never receive the session expired event.  See
+                    // http://docs.oracle.com/javase/6/docs/technotes/guides/net/articles/connection_release.html
+                    disableWrite();
                 } else {
                     // Just in case
                     enableWrite();