]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
tcpclient: catch any `socket()` errors 1821/head
author依云 <lilydjwg@gmail.com>
Mon, 5 Sep 2016 10:03:36 +0000 (18:03 +0800)
committer依云 <lilydjwg@gmail.com>
Sun, 11 Sep 2016 07:56:12 +0000 (15:56 +0800)
so we can try next addresses, e.g. when trying to connect to IPv6
addresses on OSes with IPv6 disabled which fails with a protocol not
supported error

This fixes #1809.

tornado/tcpclient.py

index f594d91b8857e69ddb772ec7e65ae5f18470ae36..111468607939fac7bd5bd1716fc46bc9663602c0 100644 (file)
@@ -177,7 +177,13 @@ class TCPClient(object):
     def _create_stream(self, max_buffer_size, af, addr):
         # Always connect in plaintext; we'll convert to ssl if necessary
         # after one connection has completed.
-        stream = IOStream(socket.socket(af),
-                          io_loop=self.io_loop,
-                          max_buffer_size=max_buffer_size)
-        return stream.connect(addr)
+        try:
+            stream = IOStream(socket.socket(af),
+                            io_loop=self.io_loop,
+                            max_buffer_size=max_buffer_size)
+        except socket.error as e:
+            fu = Future()
+            fu.set_exception(e)
+            return fu
+        else:
+            return stream.connect(addr)