Description
Up from Curator 5.7.1 calling start() on a ServiceCacheImpl instance fails with a NoAuthException if the base path of the ServiceDiscovery is read-only (e.g. world:anyone:r).
The reason for this problem is the following commit: https://github.com/apache/curator/commit/9fe79d81a8c5f2484bc29087024b5d65c8fba37f
Before, there has been an if-condition, checking with zookeeper.exists(...) if the path exists or not. Only if the path was not existing, zookeeper.create() was called. Now, zookeeper.create() is always called and the NoAuthException is not catched, resulting in the following stack trace:
Exception in thread "main" org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /test/service at org.apache.zookeeper.KeeperException.create(KeeperException.java:119) at org.apache.zookeeper.KeeperException.create(KeeperException.java:53) at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1347) at org.apache.curator.utils.ZKPaths.mkdirs(ZKPaths.java:331) at org.apache.curator.framework.imps.ExistsBuilderImpl$2.call(ExistsBuilderImpl.java:218) at org.apache.curator.framework.imps.ExistsBuilderImpl$2.call(ExistsBuilderImpl.java:214) at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:88) at org.apache.curator.framework.imps.ExistsBuilderImpl.pathInForeground(ExistsBuilderImpl.java:214) at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:202) at org.apache.curator.framework.imps.ExistsBuilderImpl.forPath(ExistsBuilderImpl.java:35) at org.apache.curator.framework.imps.CuratorFrameworkImpl.createContainers(CuratorFrameworkImpl.java:302) at org.apache.curator.framework.EnsureContainers.internalEnsure(EnsureContainers.java:63) at org.apache.curator.framework.EnsureContainers.ensure(EnsureContainers.java:50) at org.apache.curator.x.discovery.details.ServiceCacheImpl.startImmediate(ServiceCacheImpl.java:110) at org.apache.curator.x.discovery.details.ServiceCacheImpl.start(ServiceCacheImpl.java:103)
Steps to reproduce:
In Zookeeper create the node /test/service where /test serves as base path for the service discovery.
create /test create /service setAcl /test world:anyone:r
Use the following java code to reproduce the issue:
import java.util.Map; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.x.discovery.ServiceCache; import org.apache.curator.x.discovery.ServiceDiscovery; import org.apache.curator.x.discovery.ServiceDiscoveryBuilder; class Scratch { public static void main(String[] args) throws Exception { CuratorFramework curatorFramework = CuratorFrameworkFactory.builder() .connectString("localhost:2181") .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build(); curatorFramework.start(); ServiceDiscovery<Map> discovery = ServiceDiscoveryBuilder.builder(Map.class) .basePath("/test") .client(curatorFramework) .build(); discovery.start(); ServiceCache<Map> serviceCache = discovery.serviceCacheBuilder().name("service").build(); serviceCache.start(); serviceCache.close(); discovery.close(); curatorFramework.close(); } }
The code will fail on serviceCache.start() with the exception shown above.
Attachments
Issue Links
- links to