From 6fbe3006afa46c4c5f19e5c52b66e6e73a07f819 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 9 Apr 2015 00:12:41 +0200 Subject: fail gracefully if we cannot start a new thread --- netlib/tcp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'netlib/tcp.py') diff --git a/netlib/tcp.py b/netlib/tcp.py index b2f11851..45c60fd8 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -560,7 +560,11 @@ class TCPServer(object): self.address.host, self.address.port) ) t.setDaemon(1) - t.start() + try: + t.start() + except threading.ThreadError: + self.handle_error(connection, Address(client_address)) + connection.close() finally: self.__shutdown_request = False self.__is_shut_down.set() -- cgit v1.2.3 From 7f7ccd3a1865e8e73f3d1813182d01c607d6e501 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 9 Apr 2015 00:57:37 +0200 Subject: 100% test coverage --- netlib/tcp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'netlib/tcp.py') diff --git a/netlib/tcp.py b/netlib/tcp.py index 45c60fd8..20e7d45f 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -302,7 +302,7 @@ class _Connection(object): self.connection.shutdown() except SSL.Error: pass - except KeyError as e: + except KeyError as e: # pragma: no cover # Workaround for https://github.com/pyca/pyopenssl/pull/183 if OpenSSL.__version__ != "0.14": raise e -- cgit v1.2.3 From e58f76aec1db9cc784a3b73c3050d010bb084968 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 9 Apr 2015 02:09:33 +0200 Subject: fix code smell --- netlib/tcp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'netlib/tcp.py') diff --git a/netlib/tcp.py b/netlib/tcp.py index 20e7d45f..10269aa4 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -64,7 +64,7 @@ class SSLKeyLogger(object): log_ssl_key = SSLKeyLogger.create_logfun(os.getenv("MITMPROXY_SSLKEYLOGFILE") or os.getenv("SSLKEYLOGFILE")) -class _FileLike: +class _FileLike(object): BLOCKSIZE = 1024 * 32 def __init__(self, o): self.o = o @@ -134,8 +134,8 @@ class Writer(_FileLike): r = self.o.write(v) self.add_log(v[:r]) return r - except (SSL.Error, socket.error), v: - raise NetLibDisconnect(str(v)) + except (SSL.Error, socket.error) as e: + raise NetLibDisconnect(str(e)) class Reader(_FileLike): @@ -546,10 +546,10 @@ class TCPServer(object): try: r, w, e = select.select([self.socket], [], [], poll_interval) except select.error as ex: # pragma: no cover - if ex[0] == EINTR: - continue - else: - raise + if ex[0] == EINTR: + continue + else: + raise if self.socket in r: connection, client_address = self.socket.accept() t = threading.Thread( -- cgit v1.2.3