Skip to content

Commit

Permalink
fix(core): Use a copy of auth data when reconnecting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arushiagg authored and Arushi Aggarwal committed Oct 2, 2018
1 parent 60366d2 commit 271c13d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Zookeeper Protocol Connection Handler"""
from binascii import hexlify
from contextlib import contextmanager
import copy
import logging
import random
import select
Expand Down Expand Up @@ -663,7 +664,10 @@ def _connect(self, host, port):
client._session_callback(KeeperState.CONNECTED)
self._ro_mode = None

for scheme, auth in client.auth_data:
# Get a copy of the auth data before iterating, in case it is
# changed.
auth_data_copy = copy.copy(client.auth_data)
for scheme, auth in auth_data_copy:
ap = Auth(0, scheme, auth)
zxid = self._invoke(connect_timeout / 1000.0, ap, xid=AUTH_XID)
if zxid:
Expand Down

0 comments on commit 271c13d

Please sign in to comment.