[Python-checkins] bpo-33674: Pause the transport as early as possible (GH-7192)

Miss Islington (bot) webhook-mailer at python.org
Tue May 29 01:59:06 EDT 2018


https://github.com/python/cpython/commit/eca085993cb8620ba9232560f46d91326a13cdd2
commit: eca085993cb8620ba9232560f46d91326a13cdd2
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-05-28T22:59:03-07:00
summary:

bpo-33674: Pause the transport as early as possible (GH-7192)

(cherry picked from commit f295587c45f96b62d24f9a12cef6931b0805f596)

Co-authored-by: Yury Selivanov <yury at magic.io>

files:
A Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst
M Lib/asyncio/base_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index ffd2513e33a6..61938e90c375 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -1106,10 +1106,13 @@ def _check_sendfile_params(self, sock, file, offset, count):
             ssl_handshake_timeout=ssl_handshake_timeout,
             call_connection_made=False)
 
+        # Pause early so that "ssl_protocol.data_received()" doesn't
+        # have a chance to get called before "ssl_protocol.connection_made()".
+        transport.pause_reading()
+
         transport.set_protocol(ssl_protocol)
         self.call_soon(ssl_protocol.connection_made, transport)
-        if not transport.is_reading():
-            self.call_soon(transport.resume_reading)
+        self.call_soon(transport.resume_reading)
 
         await waiter
         return ssl_protocol._app_transport
diff --git a/Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst b/Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst
new file mode 100644
index 000000000000..66baca16d69f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst
@@ -0,0 +1,2 @@
+Pause the transport as early as possible to further reduce the risk of
+data_received() being called before connection_made().



More information about the Python-checkins mailing list