Skip to content

Instantly share code, notes, and snippets.

@azat
Created December 28, 2022 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/bc7aaea1c32a4f1ea75ad646d26280e9 to your computer and use it in GitHub Desktop.
Save azat/bc7aaea1c32a4f1ea75ad646d26280e9 to your computer and use it in GitHub Desktop.
Endless wait in kazoo after AUTH_FAILED on stop
diff --git a/kazoo/client.py b/kazoo/client.py
index 27b7c38..0c0ecc0 100644
--- a/kazoo/client.py
+++ b/kazoo/client.py
@@ -400,6 +400,7 @@ class KazooClient(object):
def _reset(self):
"""Resets a variety of client states for a new connection."""
+ self.logger.log(BLATHER, "Reseting the client")
self._queue = deque()
self._pending = deque()
@@ -717,6 +718,7 @@ class KazooClient(object):
return
self._stopped.set()
+ self.logger.log(BLATHER, "Sending CloseInstance")
self._queue.append((CloseInstance, None))
try:
self._connection._write_sock.send(b"\0")
diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py
index 9b5ce2f..8ca7293 100644
--- a/kazoo/protocol/connection.py
+++ b/kazoo/protocol/connection.py
@@ -580,6 +580,8 @@ class ConnectionHandler(object):
if len(host_ports) == 0:
raise ForceRetryError("No host resolved. Reconnecting")
+ self.logger.log(BLATHER, "Connecting")
+
for host, hostip, port in host_ports:
if self.client._stopped.is_set():
status = STOP_CONNECTING
@@ -619,7 +621,9 @@ class ConnectionHandler(object):
self.ping_outstanding.clear()
last_send = time.time()
with self._socket_error_handling():
while True:
+ self.logger.log(BLATHER, "Connecting")
+
# Watch for something to read or send
jitter_time = random.randint(1, 40) / 100.0
deadline = last_send + read_timeout / 2.0 - jitter_time
$ PYTHONPATH=$PWD pytest --log-cli-date-format="%S" --log-cli-format='%(asctime)s: [ %(threadName)s ] %(levelname)s: %(filename)s:%(lineno)s: %(funcName)s: %(message)s' --log-cli-level=5 /tmp/test_kazoo.py
================================================================================ test session starts =================================================================================
platform linux -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
rootdir: /tmp
plugins: timeout-2.1.0, anyio-3.6.2, mock-3.10.0
collected 1 item
../../../tmp/test_kazoo.py::test_kazoo
----------------------------------------------------------------------------------- live log call ------------------------------------------------------------------------------------
39: [ MainThread ] Level 5: client.py:403: _reset: Reseting the client
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:536: zk_loop: ZK loop started
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:583: _connect_loop: Connecting
39: [ Thread-3 (zk_loop) ] Level 5: client.py:558: _session_callback: Skipping state change
39: [ Thread-3 (zk_loop) ] INFO: connection.py:692: _connect: Connecting to 127.0.0.1(127.0.0.1):9181, use_ssl: False
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:700: _connect: Using session_id: None session_passwd: b'00000000000000000000000000000000'
39: [ Thread-3 (zk_loop) ] DEBUG: connection.py:330: _submit: Sending request(xid=None): Connect(protocol_version=0, last_zxid_seen=0, time_out=10000, session_id=0, passwd=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', read_only=None)
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:316: _invoke: Read response Connect(protocol_version=0, last_zxid_seen=0, time_out=10000, session_id=225, passwd=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', read_only=False)
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:748: _connect: Session created, session_id: 225 session_passwd: b'00000000000000000000000000000000'
negotiated session timeout: 10000
connect timeout: 10000.0
read timeout: 6666.666666666667
39: [ Thread-3 (zk_loop) ] INFO: client.py:562: _session_callback: Zookeeper connection established, state: CONNECTED
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
39: [ Thread-3 (zk_loop) ] DEBUG: connection.py:330: _submit: Sending request(xid=-4): Auth(auth_type=0, scheme='world', auth='anyone')
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:472: _read_socket: Received AUTH
39: [ Thread-3 (zk_loop) ] INFO: client.py:568: _session_callback: Zookeeper session closed, state: AUTH_FAILED
39: [ MainThread ] Level 5: client.py:721: stop: Sending CloseInstance
39: [ Thread-3 (zk_loop) ] Level 5: client.py:403: _reset: Reseting the client
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
39: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
42: [ Thread-3 (zk_loop) ] Level 5: connection.py:330: _submit: Sending request(xid=-2): Ping()
42: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
42: [ Thread-3 (zk_loop) ] Level 5: connection.py:469: _read_socket: Received Ping
42: [ Thread-3 (zk_loop) ] Level 5: connection.py:625: _connect_attempt: Connecting
^C
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/usr/lib/python3.10/threading.py:324: KeyboardInterrupt
(to show a full traceback on KeyboardInterrupt use --full-trace)
=============================================================================== no tests ran in 6.44s ================================================================================
import pytest
from kazoo.client import KazooClient
from kazoo.exceptions import AuthFailedError
def get_zk():
zk = KazooClient(hosts="127.0.0.1:9181")
zk.start()
return zk
def test_kazoo():
no_auth_connection = get_zk()
with pytest.raises(AuthFailedError):
no_auth_connection.add_auth("world", "anyone")
no_auth_connection.stop()
@azat
Copy link
Author

azat commented Dec 28, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment