From b1461aa78139cd849b507049a77ad2635b78f8a3 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 16 Dec 2016 11:50:41 -0500 Subject: [PATCH] Issue #28990: Fix SSL hanging if connection is closed before handshake completed. --- Lib/asyncio/sslproto.py | 1 + Lib/test/test_asyncio/test_sslproto.py | 10 ++++++++++ Misc/NEWS | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 804c5c30f13..c2c4b95fcbc 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -479,6 +479,7 @@ class SSLProtocol(protocols.Protocol): 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 diff --git a/Lib/test/test_asyncio/test_sslproto.py b/Lib/test/test_asyncio/test_sslproto.py index 0ca6d1bf2aa..59ff0f6967e 100644 --- a/Lib/test/test_asyncio/test_sslproto.py +++ b/Lib/test/test_asyncio/test_sslproto.py @@ -85,5 +85,15 @@ class SslProtoHandshakeTests(test_utils.TestCase): # 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() diff --git a/Misc/NEWS b/Misc/NEWS index f16d207464b..806a603b907 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -485,6 +485,10 @@ Library - Issue #24142: Reading a corrupt config file left the parser in an invalid state. Original patch by Florian Höch. +- Issue #28990: Fix SSL hanging if connection is closed before handshake + completed. + (Patch by HoHo-Ho) + IDLE ----