Skip to content

Commit de20be9

Browse files
arushiaggjeffwidman
authored andcommitted
fix(core): Use a copy of auth data when reconnecting (#509)
It is possible to race between processing a new addAuth request(which updates the client.auth_data set) and iterating through it during reconnect. To avoid set changes during iteration, make a copy.
1 parent aa2664b commit de20be9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

kazoo/protocol/connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Zookeeper Protocol Connection Handler"""
22
from binascii import hexlify
33
from contextlib import contextmanager
4+
import copy
45
import logging
56
import random
67
import select
@@ -687,9 +688,14 @@ def _connect(self, host, port):
687688
self._ro_mode = iter(self._server_pinger())
688689
else:
689690
self._ro_mode = None
691+
692+
# Get a copy of the auth data before iterating, in case it is
693+
# changed.
694+
client_auth_data_copy = copy.copy(client.auth_data)
695+
690696
if client.use_sasl and self.sasl_cli is None:
691697
if PURESASL_AVAILABLE:
692-
for scheme, auth in client.auth_data:
698+
for scheme, auth in client_auth_data_copy:
693699
if scheme == 'sasl':
694700
username, password = auth.split(":")
695701
self.sasl_cli = SASLClient(
@@ -717,7 +723,7 @@ def _connect(self, host, port):
717723
client._session_callback(KeeperState.CONNECTED)
718724
else:
719725
client._session_callback(KeeperState.CONNECTED)
720-
for scheme, auth in client.auth_data:
726+
for scheme, auth in client_auth_data_copy:
721727
if scheme == "digest":
722728
ap = Auth(0, scheme, auth)
723729
zxid = self._invoke(

0 commit comments

Comments
 (0)