From d279f8f90b73a3a3c038aac74d3d73ce5423eb08 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 4 Jun 2018 13:46:44 -0400 Subject: [PATCH 1/3] bpo-33769: start_tls:Fix error message; cancel callbacks in case of an error --- Lib/asyncio/base_events.py | 8 +++++--- .../next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 34cc6252e77cb6..68a1ebe623b871 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1097,7 +1097,7 @@ async def start_tls(self, transport, protocol, sslcontext, *, if not getattr(transport, '_start_tls_compatible', False): raise TypeError( - f'transport {self!r} is not supported by start_tls()') + f'transport {transport!r} is not supported by start_tls()') waiter = self.create_future() ssl_protocol = sslproto.SSLProtocol( @@ -1111,13 +1111,15 @@ async def start_tls(self, transport, protocol, sslcontext, *, transport.pause_reading() transport.set_protocol(ssl_protocol) - self.call_soon(ssl_protocol.connection_made, transport) - self.call_soon(transport.resume_reading) + conmade_cb = self.call_soon(ssl_protocol.connection_made, transport) + resume_cb = self.call_soon(transport.resume_reading) try: await waiter except Exception: transport.close() + conmade_cb.cancel() + resume_cb.cancel() raise return ssl_protocol._app_transport diff --git a/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst b/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst new file mode 100644 index 00000000000000..d72e70b66f2b60 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst @@ -0,0 +1,2 @@ +asyncio/start_tls: Fix error message; cancel callbacks in case of an +unhandled error From 45ac2570467e0da7face8d0caaf985081a3e1f85 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 4 Jun 2018 18:42:23 -0400 Subject: [PATCH 2/3] SSLTransport.abort() should mark itself as closed --- Lib/asyncio/sslproto.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 8515ec5eebd32e..fac2ae74e808b8 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -399,6 +399,7 @@ def abort(self): called with None as its argument. """ self._ssl_protocol._abort() + self._closed = True class SSLProtocol(protocols.Protocol): From 75d82b101208a00a482172ae6efd9b1fd68a8ad2 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Mon, 4 Jun 2018 18:46:28 -0400 Subject: [PATCH 3/3] Update news --- .../next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst b/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst index d72e70b66f2b60..9a124fafc6d24f 100644 --- a/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst +++ b/Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst @@ -1,2 +1,2 @@ asyncio/start_tls: Fix error message; cancel callbacks in case of an -unhandled error +unhandled error; mark SSLTransport as closed if it is aborted.