Skip to content

Commit

Permalink
SSL hangs if connection_lost is called (python#472) (python#476)
Browse files Browse the repository at this point in the history
There were situations when yield from waiter hangs.
For example if connection is aborted by peer before
handshake completes.
  • Loading branch information
HoHo-Ho authored and gvanrossum committed Dec 16, 2016
1 parent 3878fa8 commit d84a8cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def connection_lost(self, exc):
self._loop.call_soon(self._app_protocol.connection_lost, exc)
self._transport = None
self._app_transport = None
self._wakeup_waiter(exc)

def pause_writing(self):
"""Called when the low-level transport's buffer goes over
Expand Down
10 changes: 10 additions & 0 deletions tests/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,15 @@ def test_fatal_error_no_name_error(self):
# Restore error logging.
log.logger.setLevel(log_level)

def test_connection_lost(self):
# From issue #472.
# yield from waiter hang if lost_connection was called.
waiter = asyncio.Future(loop=self.loop)
ssl_proto = self.ssl_protocol(waiter)
self.connection_made(ssl_proto)
ssl_proto.connection_lost(ConnectionAbortedError)
test_utils.run_briefly(self.loop)
self.assertIsInstance(waiter.exception(), ConnectionAbortedError)

if __name__ == '__main__':
unittest.main()

0 comments on commit d84a8cb

Please sign in to comment.