Skip to content

Commit 5225b3e

Browse files
authored
Fix possible endless wait in stop() after AUTH_FAILED error (#688)
In case of AUTH_FAILED in the zk-loop thread it will call client._session_callback which will reset the queue. However another thread can add to this queue CloseInstance event, and if the _session_callback() will be called after CloseInstance was added to the queue, then stop() will never return (and zk-loop will endlessly spin). Here is how it looks like with addititional logging: 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 You can find details in this gist [1]. [1]: https://gist.github.com/azat/bc7aaea1c32a4f1ea75ad646d26280e9
1 parent 92b071d commit 5225b3e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

kazoo/protocol/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def _connect_attempt(self, host, hostip, port, retry):
619619
self.ping_outstanding.clear()
620620
last_send = time.time()
621621
with self._socket_error_handling():
622-
while True:
622+
while not self.client._stopped.is_set():
623623
# Watch for something to read or send
624624
jitter_time = random.randint(1, 40) / 100.0
625625
deadline = last_send + read_timeout / 2.0 - jitter_time

kazoo/tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ def test_async_auth_failure(self):
256256
with pytest.raises(AuthFailedError):
257257
client.add_auth("unknown-scheme", digest_auth)
258258

259+
client.stop()
260+
259261
def test_add_auth_on_reconnect(self):
260262
client = self._get_client()
261263
client.start()

0 commit comments

Comments
 (0)