Skip to content

Commit 415bc46

Browse files
authored
bpo-33769: start_tls: Fix error message; cancel callbacks on error (GH-7403)
In addition to that, mark SSLTransport as "closed" in its "abort()" method to prevent bogus warnings.
1 parent e9e3976 commit 415bc46

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Lib/asyncio/base_events.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ async def start_tls(self, transport, protocol, sslcontext, *,
10971097

10981098
if not getattr(transport, '_start_tls_compatible', False):
10991099
raise TypeError(
1100-
f'transport {self!r} is not supported by start_tls()')
1100+
f'transport {transport!r} is not supported by start_tls()')
11011101

11021102
waiter = self.create_future()
11031103
ssl_protocol = sslproto.SSLProtocol(
@@ -1111,13 +1111,15 @@ async def start_tls(self, transport, protocol, sslcontext, *,
11111111
transport.pause_reading()
11121112

11131113
transport.set_protocol(ssl_protocol)
1114-
self.call_soon(ssl_protocol.connection_made, transport)
1115-
self.call_soon(transport.resume_reading)
1114+
conmade_cb = self.call_soon(ssl_protocol.connection_made, transport)
1115+
resume_cb = self.call_soon(transport.resume_reading)
11161116

11171117
try:
11181118
await waiter
11191119
except Exception:
11201120
transport.close()
1121+
conmade_cb.cancel()
1122+
resume_cb.cancel()
11211123
raise
11221124

11231125
return ssl_protocol._app_transport

Lib/asyncio/sslproto.py

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def abort(self):
399399
called with None as its argument.
400400
"""
401401
self._ssl_protocol._abort()
402+
self._closed = True
402403

403404

404405
class SSLProtocol(protocols.Protocol):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
asyncio/start_tls: Fix error message; cancel callbacks in case of an
2+
unhandled error; mark SSLTransport as closed if it is aborted.

0 commit comments

Comments
 (0)