]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-33674: asyncio: Fix SSLProtocol race (GH-7175)
authorVictor Stinner <vstinner@redhat.com>
Mon, 28 May 2018 23:33:35 +0000 (01:33 +0200)
committerGitHub <noreply@github.com>
Mon, 28 May 2018 23:33:35 +0000 (01:33 +0200)
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.

Lib/asyncio/sslproto.py
Misc/NEWS.d/next/Library/2018-05-28-22-49-59.bpo-33674.6LFFj7.rst [new file with mode: 0644]

index 2bfa45dd1585afa4290579a15f1aa07fb9fb6371..ab43e93b28bc7825ff82f6d0ef9c33782129ad0a 100644 (file)
@@ -592,10 +592,10 @@ class SSLProtocol(protocols.Protocol):
         # (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 (file)
index 0000000..1e98680
--- /dev/null
@@ -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.