Signed-off-by: Kai Zhang <kyle at zelin.io> --- sheep/cluster/zookeeper.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c index 5f5e867..d144fa7 100644 --- a/sheep/cluster/zookeeper.c +++ b/sheep/cluster/zookeeper.c @@ -491,7 +491,7 @@ static int add_join_event(void *msg, size_t msg_len) static int zk_join(const struct sd_node *myself, void *opaque, size_t opaque_len) { - int rc; + int rc, sleep_ms; char path[MAX_NODE_STR_LEN]; this_node.node = *myself; @@ -499,8 +499,15 @@ static int zk_join(const struct sd_node *myself, snprintf(path, sizeof(path), MEMBER_ZNODE "/%s", node_to_str(myself)); rc = zk_node_exists(path); if (rc == ZOK) { - sd_eprintf("Previous zookeeper session exist, shoot myself."); - exit(1); + /* wait for previous session timeout */ + sleep_ms = zoo_recv_timeout(zhandle); + usleep(sleep_ms * 1000); + rc = zk_node_exists(path); + if (rc == ZOK) { + sd_eprintf("Previous zookeeper session exist," + " shoot myself."); + exit(1); + } } /* For concurrent nodes setup, we allow only one to continue */ -- 1.7.1 |