timeout param is not respected
Expected Behavior
- The default
timeoutis respected. - If specified, the
timeoutis respected.
Actual Behavior
The computers on which the 3 ZK servers run are deliberately OFF. Run the client from a forth computer.
In the client code, define 3 hosts in the KazooClient() statement. The start() statement that follows, cycles through the hosts in about 5 seconds per host. Not 10 as expected.
Setting the timeout in the call to KazooClient() or start() does not change this duration.
Snippet to Reproduce the Problem
zk = KazooClient(hosts='rpi17.local:2181,rpi18.local:2181,rpi19.local:2181') # Adding timeout param does not change behavior
zk.start()` # or zk.start(timeout=15)
Logs with logging in DEBUG mode
Cannot resolve rpi17.local: [Errno 8] nodename nor servname provided, or not known
Cannot resolve rpi18.local: [Errno 8] nodename nor servname provided, or not known
Cannot resolve rpi19.local: [Errno 8] nodename nor servname provided, or not known
Failed connecting to Zookeeper within the connection retry policy.
Traceback (most recent call last):
File "/Users/Dropbox/Idempotent/ZooKeeper/zkMyCli.py", line 441, in
Specifications
- Kazoo version: 2.10.0
- Result of
pip listcommand: kazoo 2.10.0 - Zookeeper version: 3.8.4
- Zookeeper configuration:
- Python version: 3.11.5
- OS: macOS
Hello,
Thank you for the issue.
In the example and logs you've given, I don't think there is any way to get the "10s per host timeout" you would expect with Kazoo as the error you are getting is a DNS error that prevents Kazoo for making a connection since, well, your hostnames cannot be resolved to a valid IP address. Most of the time there is a 5s timeout for resolving a hostname so that's why you are noticing that specific value. You could probably update your system DNS settings to achieve what you want (maybe some options timeout:10 would work).
With Kazoo, you could make use of some KazooRetry() to retry more, for instance:
from kazoo.client import KazooClient
from kazoo.retry import KazooRetry
zk = KazooClient(hosts='rpi17.local:2181,rpi18.local:2181,rpi19.local:2181', connection_retry=KazooRetry(max_tries=-1)) # infinite retries
zk.start(timeout=30) # wait for 30s... or more depending on the number of hosts + DNS setting