From 33eba29d1e6801af1b2e067503a2f505be3f489b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 12 May 2018 12:36:31 +1200 Subject: tcp: handle EINVAL from closed connections Fixes #2771 --- mitmproxy/net/tcp.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py index 18429daa..23284057 100644 --- a/mitmproxy/net/tcp.py +++ b/mitmproxy/net/tcp.py @@ -1,4 +1,5 @@ import os +import errno import select import socket import sys @@ -585,6 +586,13 @@ class TCPServer: with self.handler_counter: try: self.handle_client_connection(connection, client_address) + except OSError as e: + # This catches situations where the underlying connection is + # closed beneath us. Syscalls on the connection object at this + # point returns EINVAL. If this happens, we close the socket and + # move on. + if not e.errno == errno.EINVAL: + raise except: self.handle_error(connection, client_address) finally: -- cgit v1.2.3