From 042dad7232a021e6c848f1368e75d8b3e5ce0dbe Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 15 Jan 2015 09:41:48 +0100 Subject: [PATCH 1/2] Issue #22560: Fix SSLProtocol._on_handshake_complete() Don't call immediatly self._process_write_backlog() but schedule the call using call_soon(). _on_handshake_complete() can be called indirectly from _process_write_backlog(), and _process_write_backlog() is not reentrant. --- Lib/asyncio/sslproto.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 541e252774e..31eab51ca17 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -572,8 +572,12 @@ class SSLProtocol(protocols.Protocol): # wait until protocol.connection_made() has been called self._waiter._set_result_unless_cancelled(None) self._session_established = True - # In case transport.write() was already called - self._process_write_backlog() + # In case transport.write() was already called. Don't call + # immediatly _process_write_backlog(), but schedule it: + # _on_handshake_complete() can be called indirectly from + # _process_write_backlog(), and _process_write_backlog() is not + # reentrant. + self._loop.call(self._process_write_backlog) def _process_write_backlog(self): # Try to make progress on the write backlog. From 72bdefb0868771d360385da55750e8742dab3e05 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 15 Jan 2015 09:44:13 +0100 Subject: [PATCH 2/2] Issue #22560: Fix typo: call -> call_soon --- Lib/asyncio/sslproto.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/sslproto.py b/Lib/asyncio/sslproto.py index 31eab51ca17..c7fb4e7c60f 100644 --- a/Lib/asyncio/sslproto.py +++ b/Lib/asyncio/sslproto.py @@ -577,7 +577,7 @@ class SSLProtocol(protocols.Protocol): # _on_handshake_complete() can be called indirectly from # _process_write_backlog(), and _process_write_backlog() is not # reentrant. - self._loop.call(self._process_write_backlog) + self._loop.call_soon(self._process_write_backlog) def _process_write_backlog(self): # Try to make progress on the write backlog.