]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
tcpclient: Close socket on source_ip bind failure
authorBen Darnell <ben@bendarnell.com>
Mon, 20 Feb 2017 19:18:22 +0000 (14:18 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 20 Feb 2017 19:18:22 +0000 (14:18 -0500)
Silences a warning on python 3

tornado/tcpclient.py

index 1e289174525d610891585c3f2223c33334bc8e2f..244966ca4a71eebec25e1cb61e3371bc796ebe84 100644 (file)
@@ -201,8 +201,12 @@ class TCPClient(object):
         socket_obj = socket.socket(af)
         if source_port_bind or source_ip_bind:
             # If the user requires binding also to a specific IP/port.
-            socket_obj.bind((source_ip_bind, source_port_bind))
-            # Fail loudly if unable to use the IP/port.
+            try:
+                socket_obj.bind((source_ip_bind, source_port_bind))
+            except socket.error:
+                socket_obj.close()
+                # Fail loudly if unable to use the IP/port.
+                raise
         try:
             stream = IOStream(socket_obj,
                               io_loop=self.io_loop,