From: Ben Darnell Date: Mon, 20 Feb 2017 19:18:22 +0000 (-0500) Subject: tcpclient: Close socket on source_ip bind failure X-Git-Tag: v4.5.0~36^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad09f9111e6ccc9ad17094695c6c2e999b5dc011;p=thirdparty%2Ftornado.git tcpclient: Close socket on source_ip bind failure Silences a warning on python 3 --- diff --git a/tornado/tcpclient.py b/tornado/tcpclient.py index 1e2891745..244966ca4 100644 --- a/tornado/tcpclient.py +++ b/tornado/tcpclient.py @@ -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,