]> granicus.if.org Git - python/commitdiff
bpo-33769: start_tls: Fix error message; cancel callbacks on error (GH-7403)
authorYury Selivanov <yury@magic.io>
Tue, 5 Jun 2018 12:59:58 +0000 (08:59 -0400)
committerGitHub <noreply@github.com>
Tue, 5 Jun 2018 12:59:58 +0000 (08:59 -0400)
In addition to that, mark SSLTransport as "closed" in its "abort()" method to prevent bogus warnings.

Lib/asyncio/base_events.py
Lib/asyncio/sslproto.py
Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst [new file with mode: 0644]

index 34cc6252e77cb63c773d125eb6dbc98992a6cea9..68a1ebe623b87192c4da9ef95e8847c26b51df3e 100644 (file)
@@ -1097,7 +1097,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 
         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 @@ class BaseEventLoop(events.AbstractEventLoop):
         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
index 8515ec5eebd32e4cd0a5a3c4d7b2b4fa5e0ea619..fac2ae74e808b884e761102bfc89c1dec7267c71 100644 (file)
@@ -399,6 +399,7 @@ class _SSLProtocolTransport(transports._FlowControlMixin,
         called with None as its argument.
         """
         self._ssl_protocol._abort()
+        self._closed = True
 
 
 class SSLProtocol(protocols.Protocol):
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 (file)
index 0000000..9a124fa
--- /dev/null
@@ -0,0 +1,2 @@
+asyncio/start_tls: Fix error message; cancel callbacks in case of an
+unhandled error; mark SSLTransport as closed if it is aborted.