Skip to content

Commit c3f16ca

Browse files
committed
Make sure we don't hang up trying to a check if someone is
listening on our port. It might be the case that OS could block us indefinitely there.
1 parent 62343b0 commit c3f16ca

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

python/TCPProxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ def __init__(self, port, newhost, newport = None, bindhost = '127.0.0.1', logger
6565
except OSError as oex:
6666
if oex.errno != EADDRINUSE:
6767
raise oex
68+
sock.settimeout(0.1)
6869
try:
6970
sock.connect(bindaddr)
7071
raise oex
71-
except ConnectionRefusedError:
72+
except (ConnectionRefusedError, socket.timeout):
7273
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7374
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
7475
sock.bind(bindaddr)

0 commit comments

Comments
 (0)