diff options
author | arushiagg <arushi987@gmail.com> | 2018-10-06 01:07:07 -0700 |
---|---|---|
committer | Jeff Widman <jeff@jeffwidman.com> | 2018-10-06 01:07:07 -0700 |
commit | de20be917855713169863b65a7aa0634fb78b698 (patch) | |
tree | 92e4996308f2c1cd38fac79f49055a921d951074 | |
parent | aa2664b880d1456c3ccf6515c6ca42653047e272 (diff) | |
download | kazoo-de20be917855713169863b65a7aa0634fb78b698.tar.gz |
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.
-rw-r--r-- | kazoo/protocol/connection.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index 9d0e087..591ee53 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -1,6 +1,7 @@ """Zookeeper Protocol Connection Handler""" from binascii import hexlify from contextlib import contextmanager +import copy import logging import random import select @@ -687,9 +688,14 @@ class ConnectionHandler(object): self._ro_mode = iter(self._server_pinger()) else: self._ro_mode = None + + # Get a copy of the auth data before iterating, in case it is + # changed. + client_auth_data_copy = copy.copy(client.auth_data) + if client.use_sasl and self.sasl_cli is None: if PURESASL_AVAILABLE: - for scheme, auth in client.auth_data: + for scheme, auth in client_auth_data_copy: if scheme == 'sasl': username, password = auth.split(":") self.sasl_cli = SASLClient( @@ -717,7 +723,7 @@ class ConnectionHandler(object): client._session_callback(KeeperState.CONNECTED) else: client._session_callback(KeeperState.CONNECTED) - for scheme, auth in client.auth_data: + for scheme, auth in client_auth_data_copy: if scheme == "digest": ap = Auth(0, scheme, auth) zxid = self._invoke( |