Open
Description
Thank you for creating kazoo!
I use KazooClient.restart (of kazoo 2.6.1) to reconnect. But something wrong:
connection.py:618 (_connect_attempt) | Connection dropped: socket connection error: Connection refused
connection.py:647 (_connect) | Connecting to 10.222.1.17:2200, use_ssl: False
connection.py:618 (_connect_attempt) | Connection dropped: socket connection error: Connection refused
connection.py:647 (_connect) | Connecting to 10.222.1.17:2200, use_ssl: False
client.py:480 (_session_callback) | Zookeeper connection established, state: CONNECTED
connection.py:460 (_send_request) | send_request: client._queue=deque([(Close(), None)])
> This log is my output
connection.py:613 (_connect_attempt) | Closing connection to 10.222.1.17:2200
client.py:484 (_session_callback) | Zookeeper session lost, state: CLOSED
I analyzed the code.
- First, a socket connection error causes the _connect_attempt exit and so it no longer processes any request from the _read_sock.
- Then, I called the KazooClient.restart. It only calls stop and start in order.
With the stop called, it send a 'Close' request to the connection thread:
self._queue.append((CloseInstance, None))
try:
self._connection._write_sock.send(b'\0')
finally:
self._safe_close()
With the start called, it start the new connection thread, and the thread get the 'Close' request.
Therefore, it is disconnected immediately after the connection is established.
I'm not sure if I shouldn't use restart like this, or it's really a bug?