[ 
https://issues.apache.org/jira/browse/CURATOR-728?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matthias Kiefer updated CURATOR-728:
------------------------------------
    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:
{code:java}
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)
{code}
 

Steps to reproduce:

In Zookeeper create the node /test/service where /test serves as base path for 
the service discovery.
{code:java}
create /test
create /service
setAcl /test world:anyone:r {code}
Use the following java code to reproduce the issue:
{code:java}
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();
    }
} {code}
The code will fail on serviceCache.start() with the exception shown above.

  was:
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  past 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:
{code:java}
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)
{code}
 

Steps to reproduce:

In Zookeeper create the node /test/service where /test serves as base path for 
the service discovery.
{code:java}
create /test
create /service
setAcl /test world:anyone:r {code}
Use the following java code to reproduce the issue:
{code:java}
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();
    }
} {code}
The code will fail on serviceCache.start() with the exception shown above.


> ServiceCache fails to start if base path is read-only
> -----------------------------------------------------
>
>                 Key: CURATOR-728
>                 URL: https://issues.apache.org/jira/browse/CURATOR-728
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Client
>    Affects Versions: 5.7.1
>            Reporter: Matthias Kiefer
>            Priority: Major
>
> 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:
> {code:java}
> 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)
> {code}
>  
> Steps to reproduce:
> In Zookeeper create the node /test/service where /test serves as base path 
> for the service discovery.
> {code:java}
> create /test
> create /service
> setAcl /test world:anyone:r {code}
> Use the following java code to reproduce the issue:
> {code:java}
> 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();
>     }
> } {code}
> The code will fail on serviceCache.start() with the exception shown above.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to