TeskaLabs / asab

Asynchronous Server App Boilerplate (ASAB) is a micro-service framework for Python 3 and asyncio.
https://docs.teskalabs.com/asab/
BSD 3-Clause "New" or "Revised" License
28 stars 7 forks source link

Improve error handling when reconnecting to ZooKeeper #515

Open eliska-n opened 11 months ago

eliska-n commented 11 months ago

Reconnecting to ZooKeeper works nicely, but it is quite "loud" in the logs. There are uncaught exceptions propagated when ZooKeeper is not reachable.

Task exception was never retrieved
{'future': <Task finished name='Task-440' coro=<ZooKeeperContainer._readvertise() done, defined at /usr/local/lib/python3.11/dist-packages/asab/zookeeper/container.py:163> exception=SessionExpiredError()>}
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/asab/zookeeper/container.py", line 165, in _readvertise
    await adv._readvertise(self)
  File "/usr/local/lib/python3.11/dist-packages/asab/zookeeper/container.py", line 231, in _readvertise
    await zoocontainer.ZooKeeper.ProactorService.execute(check_at_zk)
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/asab/zookeeper/container.py", line 225, in check_at_zk
    if zoocontainer.ZooKeeper.Client.exists(self.RealPath):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kazoo/client.py", line 1123, in exists
    return self.exists_async(path, watch=watch).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/kazoo/handlers/utils.py", line 86, in get
    raise self._exception
kazoo.exceptions.SessionExpiredError
ateska commented 11 months ago

This is a first step, addressing "Task exception was never retrieved". The actual handling of the exception must be done in asab.zookeeper.container._readvertise() method.

https://github.com/TeskaLabs/asab/pull/517