Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to auto recovery ephemeral node when reconected? #491

Open
PWZER opened this issue Dec 18, 2017 · 0 comments
Open

How to auto recovery ephemeral node when reconected? #491

PWZER opened this issue Dec 18, 2017 · 0 comments
Labels

Comments

@PWZER
Copy link

PWZER commented Dec 18, 2017

I use kazoo.KazooRetry try to reconect, but current ephemeral node not recovery.
I want the ephemeral node automatic recovery. so what should do?

code:

retry = KazooRetry(max_tries=-1, delay=1)
zk_client = KazooClient(hosts=zk_hosts, connection_retry=retry)

def listener(state):
    if state == KazooState.CONNECTED:
        print("state: ", state)
    return False

zk_client.add_listener(listener)
zk_client.start()
node_path = "/test_env/test_node"
zk_client.create(node_path, value=b"test", ephemeral=True)

while True:
    try:
        node_exist = True if zk_client.connected and zk_client.exists(node_path) else False
    except kazoo.exceptions.ConnectionLoss:
        node_exist = False

    print("connected:", zk_client.connected, "node_exists:", node_exist)
    time.sleep(5)

output:

state:  CONNECTED
connected: True node_exists: True
connected: True node_exists: True
Connection dropped: outstanding heartbeat ping not received
Transition to CONNECTING
connected: False node_exists: False
Connection dropped: socket connection error: Can't assign requested address
Connection dropped: socket connection error: Can't assign requested address
Connection dropped: socket connection error: Can't assign requested address
connected: False node_exists: False
Connection dropped: socket connection error: Can't assign requested address
Connection dropped: socket connection error: Can't assign requested address
Connection dropped: socket connection error: Can't assign requested address
connected: False node_exists: False
connected: False node_exists: False
Session has expired
state:  CONNECTED
connected: True node_exists: False
connected: True node_exists: False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants