Skip to content

Commit

Permalink
tcpclient: catch any socket() errors
Browse files Browse the repository at this point in the history
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 tornadoweb#1809.
  • Loading branch information
lilydjwg committed Sep 11, 2016
1 parent 9d76ab9 commit e40b89a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tornado/tcpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,13 @@ def connect(self, host, port, af=socket.AF_UNSPEC, ssl_options=None,
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)

0 comments on commit e40b89a

Please sign in to comment.