Add 1 min timeout for no new data transferred

This commit is contained in:
Juhani Krekelä 2021-10-15 13:06:56 +03:00
parent 81fb82479a
commit e186c7a85d
1 changed files with 5 additions and 3 deletions

View File

@ -376,18 +376,20 @@ def proxy(sock, host):
del request_data del request_data
# TODO: Timeout
# TODO: Un-https links # TODO: Un-https links
# TODO: Keep sending request body, if any
print('', file=sys.stderr) print('', file=sys.stderr)
sock.settimeout(60)
remote_sock.settimeout(60)
while True: while True:
try: try:
data = remote_sock.recv(1024) data = remote_sock.recv(1024)
except ConnectionResetError: except (ConnectionResetError, socket.timeout):
return return
if data == b'': break if data == b'': break
try: try:
sock.sendall(data) sock.sendall(data)
except (ConnectionResetError, BrokenPipeError): except (ConnectionResetError, BrokenPipeError, socket.timeout):
break break
remote_sock.close() remote_sock.close()