From f295587c45f96b62d24f9a12cef6931b0805f596 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 29 May 2018 01:00:12 -0400 Subject: bpo-33674: Pause the transport as early as possible (#7192) --- Lib/asyncio/base_events.py | 7 +++++-- Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-05-29-00-37-56.bpo-33674.2IkGhL.rst diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index ffd2513..61938e9 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1106,10 +1106,13 @@ class BaseEventLoop(events.AbstractEventLoop): 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 0000000..66baca1 --- /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(). -- cgit v0.12