Pārlūkot izejas kodu

ZOOKEEPER-438. addauth fails to register auth on new client that's not yet connected (breed via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@788502 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 16 gadi atpakaļ
vecāks
revīzija
32b76dabd0

+ 3 - 0
CHANGES.txt

@@ -128,6 +128,9 @@ BUGFIXES:
 
 
   ZOOKEEPER-446. some traces of the host auth scheme left (breed via mahadev)
   ZOOKEEPER-446. some traces of the host auth scheme left (breed via mahadev)
 
 
+  ZOOKEEPER-438.  addauth fails to register auth on new client that's not yet
+connected (breed via mahadev)
+
 IMPROVEMENTS:
 IMPROVEMENTS:
   ZOOKEEPER-308. improve the atomic broadcast performance 3x.
   ZOOKEEPER-308. improve the atomic broadcast performance 3x.
   (breed via mahadev)
   (breed via mahadev)

+ 6 - 5
src/java/main/org/apache/zookeeper/ClientCnxn.java

@@ -1130,11 +1130,12 @@ public class ClientCnxn {
     }
     }
 
 
     public void addAuthInfo(String scheme, byte auth[]) {
     public void addAuthInfo(String scheme, byte auth[]) {
-        authInfo.add(new AuthData(scheme, auth));
-        if (zooKeeper.state == States.CONNECTED) {
-            queuePacket(new RequestHeader(-4, OpCode.auth), null,
-                    new AuthPacket(0, scheme, auth), null, null, null, null,
-                    null, null);
+        if (!zooKeeper.state.isAlive()) {
+            return;
         }
         }
+        authInfo.add(new AuthData(scheme, auth));
+        queuePacket(new RequestHeader(-4, OpCode.auth), null,
+                new AuthPacket(0, scheme, auth), null, null, null, null,
+                null, null);
     }
     }
 }
 }

+ 27 - 1
src/java/test/org/apache/zookeeper/test/ACLTest.java

@@ -55,6 +55,32 @@ public class ACLTest extends TestCase implements Watcher {
         LOG.info("FINISHED " + getName());
         LOG.info("FINISHED " + getName());
     }
     }
 
 
+    public void testDisconnectedAddAuth() throws Exception {
+        File tmpDir = ClientBase.createTmpDir();
+        ClientBase.setupTestEnv();
+        zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
+        SyncRequestProcessor.setSnapCount(1000);
+        final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
+        NIOServerCnxn.Factory f = new NIOServerCnxn.Factory(PORT);
+        f.startup(zks);
+        LOG.info("starting up the zookeeper server .. waiting");
+        assertTrue("waiting for server being up", 
+                ClientBase.waitForServerUp(HOSTPORT,CONNECTION_TIMEOUT));
+        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
+        try {
+            zk.addAuthInfo("digest", "pat:test".getBytes());
+            zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
+        } finally {
+            zk.close();
+        }
+
+        f.shutdown();
+
+        assertTrue("waiting for server down",
+                   ClientBase.waitForServerDown(HOSTPORT,
+                           ClientBase.CONNECTION_TIMEOUT));
+    }
+    
     /**
     /**
      * Verify that acl optimization of storing just
      * Verify that acl optimization of storing just
      * a few acls and there references in the data
      * a few acls and there references in the data
@@ -149,4 +175,4 @@ public class ACLTest extends TestCase implements Watcher {
             startSignal.countDown();
             startSignal.countDown();
         }
         }
     }
     }
-}
+}