Skip to content

Commit

Permalink
Expect OSError during socket shutdown, can happen if other end has …
Browse files Browse the repository at this point in the history
…already closed the socket
  • Loading branch information
abhinavsingh committed Jan 12, 2022
1 parent 3ec66ea commit ddaf616
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion proxy/core/connection/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ def _remove(self, fileno: int) -> None:
"""Remove a connection by descriptor from the internal data structure."""
conn = self.connections[fileno]
logger.debug('Removing conn#{0} from pool'.format(id(conn)))
conn.connection.shutdown(socket.SHUT_WR)
try:
conn.connection.shutdown(socket.SHUT_WR)
except OSError:
pass
conn.close()
self.pools[conn.addr].remove(conn)
del self.connections[fileno]
5 changes: 4 additions & 1 deletion proxy/http/websocket/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@ def run(self) -> None:
finally:
if not self.closed:
self.selector.unregister(self.sock)
self.sock.shutdown(socket.SHUT_WR)
try:
self.sock.shutdown(socket.SHUT_WR)
except OSError:
pass
self.sock.close()

0 comments on commit ddaf616

Please sign in to comment.