From 1037f0830a38f4e5d0ac93d624b6d7f64a72010a Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 4 Aug 2013 18:35:50 -0400 Subject: [PATCH] Less crude fix for #855: only do anything for already-connected sockets. --- tornado/iostream.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tornado/iostream.py b/tornado/iostream.py index bc4ca9287..6bdc6397b 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -801,10 +801,17 @@ class SSLIOStream(IOStream): self._handshake_writing = False self._ssl_connect_callback = None self._server_hostname = None - self._initiate_handshake() - def _initiate_handshake(self): - self._add_io_state(self.io_loop.READ | self.io_loop.WRITE) + # If the socket is already connected, attempt to start the handshake. + try: + self.socket.getpeername() + except socket.error: + pass + else: + # Indirectly start the handshake, which will run on the next + # IOLoop iteration and then the real IO state will be set in + # _handle_events. + self._add_io_state(self.io_loop.WRITE) def reading(self): return self._handshake_reading or super(SSLIOStream, self).reading() -- 2.47.2