Skip to content

Commit

Permalink
Summary: Fixed: misshandled protocol disconnect during connection setup
Browse files Browse the repository at this point in the history
If a protocol was disconnected while registering, maybe because the
server was still starting, the disconnection was handled correctly by
the Client, because the protocol attribute wasn't set, the connection
wasn't retried.
  • Loading branch information
Jim Fulton committed Jun 1, 2016
1 parent 667b23f commit 6b8003c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ZEO/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ def writeit(data):
self.heartbeat(write=False)

def connection_lost(self, exc):
logger.debug('connection_lost %r', exc)
self.heartbeat_handle.cancel()
if self.closed:
for f in self.pop_futures():
f.cancel()
else:
self.client.disconnected(self)
# We have to be careful processing the futures, because
# exception callbacks might modufy them.
for f in self.pop_futures():
f.set_exception(ClientDisconnected(exc or 'connection lost'))
self.closed = True
self.client.disconnected(self)

def finish_connect(self, protocol_version):

Expand Down Expand Up @@ -439,6 +441,7 @@ def _clear_protocols(self, protocol=None):
self.protocols = ()

def disconnected(self, protocol=None):
logger.debug('disconnected %r %r', self, protocol)
if protocol is None or protocol is self.protocol:
if protocol is self.protocol and protocol is not None:
self.client.notify_disconnected()
Expand All @@ -447,6 +450,8 @@ def disconnected(self, protocol=None):
self.connected = concurrent.futures.Future()
self.protocol = None
self._clear_protocols()

if all(p.closed for p in self.protocols):
self.try_connecting()

def upgrade(self, protocol):
Expand All @@ -457,6 +462,7 @@ def upgrade(self, protocol):
self._clear_protocols(protocol)

def try_connecting(self):
logger.debug('try_connecting')
if not self.closed:
self.protocols = [
Protocol(self.loop, addr, self,
Expand Down

0 comments on commit 6b8003c

Please sign in to comment.