Skip to content

bpo-33769: start_tls:Fix error message; cancel callbacks on error #7403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Lib/asyncio/sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def abort(self):
called with None as its argument.
"""
self._ssl_protocol._abort()
self._closed = True


class SSLProtocol(protocols.Protocol):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.