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

KazooClient.server_version() thows exception with ZooKeeper 3.6.1 server #626

Open rickrankin opened 4 years ago

rickrankin commented 4 years ago

We are in the process of upgrading ZooKeeper from 3.4.6 to 3.6.1. Upon doing so, kazoo.client.KazooClient().server_version() now throws an exception when connected to a zookeeper instance running zookeeper-3.6.1. This previously returned a valid version tuple when connecting to zookeeper-3.4.6

The ZooKeeper servers have been verified to be running. Calls to other KazooClient methods are working as expected, and ZooKeeoer utilities such as zkCli.sh are working as expected. So far, only server_version() is misbehaving.

Expected Behavior

KazooClient.server_version() method returns a valid tuple containing the zookeeper server version

Actual Behavior

A KazooException is thrown (see below).

Snippet to Reproduce the Problem

Python 3.5.6 (default, Nov 16 2018, 15:50:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from kazoo.client import KazooClient
>>> kz = KazooClient(hosts='my-zookeeper-server:2181')
>>> kz.start()
>>> kz.server_version()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/hfs/mcp/pyvenv/lib64/python3.5/site-packages/kazoo/client.py", line 787, in server_version
    % (1 + max(0, retries)))
kazoo.exceptions.KazooException: Unable to fetch useable server version after trying 4 times
>>>

Logs with logging in DEBUG mode

N/A

Specifications

StephenSorriaux commented 4 years ago

Hi,

Thanks for this issue, I will try to reproduce it.

StephenSorriaux commented 4 years ago

This is actually due to the new 4lw.commands.whitelist configuration added in Zookeeper 3.5.3 (see the docs). By default only srvr is whitelisted, but envi is required to get the Zookeeper server version. Deploying your Zookeeper servers with 4lw.commands.whitelist=srvr, envi will fix your issue.

I guess we can try to give a little more detail when the server_version() fails (or try to parse the envi is not executed because it is not in the whitelist. response the ZK server sent)

rickrankin commented 4 years ago

Thank you for investigating and pointing this out. We're coming from ZooKeeper 3.4, where this configuration item didn't exist. I've verified in our setup that whitelisting envi prevents the exception from being thrown.

I agree that a better error message might have helped. I'm not sure it would be necessary to do any parsing on the underlying response message, though. Now that I see it, just forwarding it would, I think, have given me a pretty good starting point.