mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
Check if connection is still open when trying to close
When an exception is raised during network communication with the remote close, we handle it and we close the socket. Some times, the socket is already closed due to the exception and we get an extra `OSError [Errno 107] Transport endpoint is not connected` when trying to shutdown the socket. We add a check to avoid that.
This commit is contained in:
parent
8c31ec2916
commit
2d6eefd8c6
@ -581,8 +581,12 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
|
||||
self.logger.info('bad_hostnames_ports cache size: %d',
|
||||
len(self.server.bad_hostnames_ports))
|
||||
|
||||
self._remote_server_conn.sock.shutdown(socket.SHUT_RDWR)
|
||||
self._remote_server_conn.sock.close()
|
||||
# Close the connection only if its still open. If its already
|
||||
# closed, an `OSError` "([Errno 107] Transport endpoint is not
|
||||
# connected)" would be raised.
|
||||
if not is_connection_dropped(self._remote_server_conn):
|
||||
self._remote_server_conn.sock.shutdown(socket.SHUT_RDWR)
|
||||
self._remote_server_conn.sock.close()
|
||||
raise
|
||||
finally:
|
||||
if prox_rec_res:
|
||||
|
Loading…
x
Reference in New Issue
Block a user