diff --git a/pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZookeeperBkClientFactoryImpl.java b/pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZookeeperBkClientFactoryImpl.java index aac96ce84c5c1..8cd674d580dfe 100644 --- a/pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZookeeperBkClientFactoryImpl.java +++ b/pulsar-zookeeper-utils/src/main/java/org/apache/pulsar/zookeeper/ZookeeperBkClientFactoryImpl.java @@ -55,6 +55,7 @@ public CompletableFuture create(String serverList, SessionType sessio .build(); if (zk.getState() == States.CONNECTEDREADONLY && sessionType != SessionType.AllowReadOnly) { + zk.close(); future.completeExceptionally(new IllegalStateException("Cannot use a read-only session")); }