{"record":{"id":"2b828d54373ce350","repo":"apache/pulsar","slug":"couldn-t-connect-to-zookeeper-server","errorCode":null,"errorMessage":"Couldn't connect to zookeeper server","messagePattern":"Couldn't connect to zookeeper server","errorType":"console","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/zookeeper/LocalBookkeeperEnsemble.java","lineNumber":555,"sourceCode":"        temporaryDirectories.clear();\n    }\n\n    /* Watching SyncConnected event from ZooKeeper */\n    public static class ZKConnectionWatcher implements Watcher {\n        private final CountDownLatch clientConnectLatch = new CountDownLatch(1);\n\n        @Override\n        public void process(WatchedEvent event) {\n            if (event.getState() == KeeperState.SyncConnected) {\n                clientConnectLatch.countDown();\n            }\n        }\n\n        // Waiting for the SyncConnected event from the ZooKeeper server\n        public void waitForConnection() throws IOException {\n            try {\n                if (!clientConnectLatch.await(zkSessionTimeOut, TimeUnit.MILLISECONDS)) {\n                    throw new IOException(\"Couldn't connect to zookeeper server\");\n                }\n            } catch (InterruptedException e) {\n                throw new IOException(\"Interrupted when connecting to zookeeper server\", e);\n            }\n        }\n    }\n\n    public static boolean waitForServerUp(String hp, long timeout) {\n        long start = System.currentTimeMillis();\n        String[] split = hp.split(\":\");\n        String host = split[0];\n        int port = Integer.parseInt(split[1]);\n        while (true) {\n            try {\n                Socket sock = new Socket(host, port);\n                BufferedReader reader = null;\n                try {\n                    OutputStream outstream = sock.getOutputStream();","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/zookeeper/LocalBookkeeperEnsemble.java#L537-L573","documentation":"Test/utility harness failure in LocalBookkeeperEnsemble: ZKConnectionWatcher.waitForConnection timed out (or interrupted) waiting on the connect latch for the SyncConnected event, meaning the embedded ZooKeeper server did not accept the client connection within the allotted window; commonly a dead or misconfigured local ZK during test startup.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/zookeeper/LocalBookkeeperEnsemble.java:555 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check local ZooKeeper logs for startup failure (port conflicts, disk issues)","Increase the connection wait time or retry starting the local ensemble"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}