curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jordan Zimmerman <>
Subject Re: How to recover if ZK is unavailable at Curator start up?
Date Wed, 14 May 2014 12:42:49 GMT
You can safely ignore the exception as Curator will re-register the service when the connection
heals. That said, it seems to me that registerService() should do its work in the background.
Please open an issue for this.


From: Olli Miettinen
Date: May 14, 2014 at 3:11:22 AM
Subject:  How to recover if ZK is unavailable at Curator start up?  


I'm using Curator Discovery Service to register my application's host IP address to Zookeeper.
(Curator 2.4.2 and Zookeeper 3.4.5)

If Zookeeper cluster is unavailable to my application at start-up, an exception is thrown
from ServiceDiscovery.registerService() after retries are finished.

I need my app to retry until it successfully registers to Discovery Service so can't use the
RetryPolicy as it seems to have a limited max number of retries.

Should I maybe observe the ZK connection state and register to Discover Service only after
successfully connected?
Or catch the exception and implement my own retry of registering when RetryPolicy runs out
of retries?
Other suggestions?

This is my code:

CuratorFramework client = ...
ServiceDiscovery<InstanceDetails> serviceDiscovery =  ...
ServiceInstance<InstanceDetails> serviceInstance = ...

public void start() throws Exception {
    // ...

Here's the exception I get at serviceDiscovery.registerService()

2014-05-13 16:04:25,315 [main] DEBUG org.apache.curator.RetryLoop : Retry policy not allowing
Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode
= ConnectionLoss for /discovery/myapp/
    at org.apache.zookeeper.KeeperException.create(
    at org.apache.zookeeper.KeeperException.create(
    at org.apache.zookeeper.ZooKeeper.create(
    at org.apache.curator.framework.imps.CreateBuilderImpl$
    at org.apache.curator.framework.imps.CreateBuilderImpl$
    at org.apache.curator.RetryLoop.callWithRetry(
    at org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(
    at org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(
    at org.apache.curator.framework.imps.CreateBuilderImpl.forPath(
    at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.internalRegisterService(
    at org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.registerService(
    at com.mycompany.zookeeper.discovery.MyDiscoveryClient.start(

Thanks for any advice,

View raw message