[Python-checkins] bpo-33674: asyncio: Fix SSLProtocol race (GH-7175) (#7187)

Ned Deily webhook-mailer at python.org
Mon May 28 21:44:19 EDT 2018


https://github.com/python/cpython/commit/0dd8fd03584b61cd769be88f5a2fb59b0d8f6d18
commit: 0dd8fd03584b61cd769be88f5a2fb59b0d8f6d18
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Ned Deily <nad at python.org>
date: 2018-05-28T21:44:16-04:00
summary:

bpo-33674: asyncio: Fix SSLProtocol race (GH-7175) (#7187)

Fix a race condition in SSLProtocol.connection_made() of
asyncio.sslproto: start immediately the handshake instead of using
call_soon(). Previously, data_received() could be called before the
handshake started, causing the handshake to hang or fail.
(cherry picked from commit be00a5583a2cb696335c527b921d1868266a42c6)

Co-authored-by: Victor Stinner <vstinner at redhat.com>

files:
A Misc/NEWS.d/next/Library/2018-05-28-22-49-59.bpo-33674.6LFFj7.rst
M Lib/asyncio/sslproto.py

diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py
index 2bfa45dd1585..ab43e93b28bc 100644
--- a/Lib/asyncio/sslproto.py
+++ b/Lib/asyncio/sslproto.py
@@ -592,10 +592,10 @@ def _start_handshake(self):
         # (b'', 1) is a special value in _process_write_backlog() to do
         # the SSL handshake
         self._write_backlog.append((b'', 1))
-        self._loop.call_soon(self._process_write_backlog)
         self._handshake_timeout_handle = \
             self._loop.call_later(self._ssl_handshake_timeout,
                                   self._check_handshake_timeout)
+        self._process_write_backlog()
 
     def _check_handshake_timeout(self):
         if self._in_handshake is True:
diff --git a/Misc/NEWS.d/next/Library/2018-05-28-22-49-59.bpo-33674.6LFFj7.rst b/Misc/NEWS.d/next/Library/2018-05-28-22-49-59.bpo-33674.6LFFj7.rst
new file mode 100644
index 000000000000..1e9868073f78
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-05-28-22-49-59.bpo-33674.6LFFj7.rst
@@ -0,0 +1,4 @@
+Fix a race condition in SSLProtocol.connection_made() of asyncio.sslproto:
+start immediately the handshake instead of using call_soon(). Previously,
+data_received() could be called before the handshake started, causing the
+handshake to hang or fail.



More information about the Python-checkins mailing list