From: Ben Darnell Date: Sat, 2 Jul 2011 20:08:03 +0000 (-0700) Subject: Properly check for errors on async connect instead of relying on the order X-Git-Tag: v2.1.0~136^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39935ac5a3f4b8f9fe67a4e9ef992c6d065907ef;p=thirdparty%2Ftornado.git Properly check for errors on async connect instead of relying on the order of events from the IOLoop. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 3ae241c2c..7a675280f 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -365,6 +365,16 @@ class IOStream(object): return False def _handle_connect(self): + err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) + if err != 0: + # IOLoop implementations may vary: some of them return + # an error state before the socket becomes writable, so + # in that case a connection failure would be handled by the + # error path in _handle_events instead of here. + logging.warning("Connect error on fd %d: %s", + self.socket.fileno(), errno.errorcode[err]) + self.close() + return if self._connect_callback is not None: callback = self._connect_callback self._connect_callback = None