[Python-checkins] bpo-33769: start_tls: Fix error message; cancel callbacks on error (GH-7403) (GH-7428)
Yury Selivanov
webhook-mailer at python.org
Tue Jun 5 10:18:23 EDT 2018
https://github.com/python/cpython/commit/79c7e57c46a9e5ae2b99a821e152f334b775df2d
commit: 79c7e57c46a9e5ae2b99a821e152f334b775df2d
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Yury Selivanov <yury at magic.io>
date: 2018-06-05T10:18:20-04:00
summary:
bpo-33769: start_tls: Fix error message; cancel callbacks on error (GH-7403) (GH-7428)
In addition to that, mark SSLTransport as "closed" in its "abort()" method to prevent bogus warnings.
(cherry picked from commit 415bc46a78e785f357c8960ae70f18a6b6cccbb6)
Co-authored-by: Yury Selivanov <yury at magic.io>
files:
A Misc/NEWS.d/next/Library/2018-06-04-13-46-39.bpo-33769.D_pxYz.rst
M Lib/asyncio/base_events.py
M Lib/asyncio/sslproto.py
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 34cc6252e77c..68a1ebe623b8 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1097,7 +1097,7 @@ def _check_sendfile_params(self, sock, file, offset, count):
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 @@ def _check_sendfile_params(self, sock, file, offset, count):
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/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 8515ec5eebd3..fac2ae74e808 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):
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 000000000000..9a124fafc6d2
--- /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; mark SSLTransport as closed if it is aborted.
More information about the Python-checkins
mailing list