python-zk / kazoo

Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
https://kazoo.readthedocs.io
Apache License 2.0
1.3k stars 387 forks source link

Zookeeper client disconnects and reconnects with an error #556

Open ChenJhua opened 5 years ago

ChenJhua commented 5 years ago
  1. start python process,create zk client,hosts has two effective zk server
  2. find zk client connect zk server and kill this zk server
  3. don't reconnect other zk server and has exception
  4. I use or not use kazooretry has simple exception
  5. I use connection_listener has simple exception
    Traceback (most recent call last):
    File "dmoc_update_cfg.py", line 110, in <module>
    update_cfg.create_tem_node(hid)
    File "dmoc_update_cfg.py", line 35, in create_tem_node
    if not self.kr(self.zk_obj.exists, self.path):
    File "/usr/lib/python2.7/site-packages/kazoo/retry.py", line 129, in __call__
    return func(*args, **kwargs)
    File "/usr/lib/python2.7/site-packages/kazoo/client.py", line 1033, in exists
    return self.exists_async(path, watch=watch).get()
    File "/usr/lib/python2.7/site-packages/kazoo/handlers/utils.py", line 69, in get
    raise self._exception
    kazoo.exceptions.SessionExpiredError

    I don't know why has exception and reconnect effective zk server need do something?

StephenSorriaux commented 5 years ago

Hi,

Sounds related to https://github.com/python-zk/kazoo/issues/457

ChenJhua commented 5 years ago

I trying #457 ,but not use; If I have three hosts A,B,C, and kazoo client connecting to A, then if I kill A, kazoo client will connect to two other useful hosts B,C, such as B. But if I start A now and kill B, kazoo client will not select A, because A has been removed from the list of valid hosts?

StephenSorriaux commented 5 years ago

A is not removed from the list. If you set hosts to A, B and C, you will first connect to A, If you get disconnected from A, you will connect to B. Again, if you get disconnected from B, you will move to C. And so on.

ChenJhua commented 5 years ago

Yeah,I know it,but during this period, A is back to normal, can we connect to A? Do you use the list to mark invalid hosts or valid hosts and remove them from the list if they cannot be connected?

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/kazoo/client.py", line 1033, in exists
    return self.exists_async(path, watch=watch).get()
  File "/usr/lib/python2.7/site-packages/kazoo/handlers/utils.py", line 69, in get
    raise self._exception
kazoo.exceptions.SessionExpiredError

when I capture SessionExpiredError exception,I use kazoo client _reset(),B server down will reconnect to A。

Using _reset() has those effects?