]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Properly check for errors on async connect instead of relying on the order
authorBen Darnell <ben@bendarnell.com>
Sat, 2 Jul 2011 20:08:03 +0000 (13:08 -0700)
committerBen Darnell <ben@bendarnell.com>
Sat, 2 Jul 2011 20:08:03 +0000 (13:08 -0700)
of events from the IOLoop.

tornado/iostream.py

index 3ae241c2c50af74b4e670df91a653e850846c975..7a675280f6c049e77229dd9c6a56ffb63968bbf4 100644 (file)
@@ -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