diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-11 19:52:24 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-11 19:52:24 +1200 |
commit | 09edbd9492e59c0c8dcae69b4b1f4b745867abe4 (patch) | |
tree | e9cf29c394334c02d908058c2c5e159715d3e3c3 /mitmproxy | |
parent | 5b9f07c81c0dcc8c7b3d7afdeae8f6229ebf8622 (diff) | |
download | mitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.tar.gz mitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.tar.bz2 mitmproxy-09edbd9492e59c0c8dcae69b4b1f4b745867abe4.zip |
Improve debugging of thread and other leaks
- Add basethread.BaseThread that all threads outside of test suites should use
- Add a signal handler to mitmproxy, mitmdump and mitmweb that dumps resource
information to screen when SIGUSR1 is received.
- Improve thread naming throughout to make thread dumps understandable
Diffstat (limited to 'mitmproxy')
-rw-r--r-- | mitmproxy/controller.py | 9 | ||||
-rw-r--r-- | mitmproxy/main.py | 1 | ||||
-rw-r--r-- | mitmproxy/protocol/http2.py | 7 | ||||
-rw-r--r-- | mitmproxy/protocol/http_replay.py | 8 | ||||
-rw-r--r-- | mitmproxy/script/concurrent.py | 9 |
5 files changed, 23 insertions, 11 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 084702a6..898be3bc 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -5,8 +5,10 @@ import threading from six.moves import queue +from netlib import basethread from mitmproxy import exceptions + Events = frozenset([ "clientconnect", "clientdisconnect", @@ -95,12 +97,13 @@ class Master(object): self.should_exit.set() -class ServerThread(threading.Thread): +class ServerThread(basethread.BaseThread): def __init__(self, server): self.server = server - super(ServerThread, self).__init__() address = getattr(self.server, "address", None) - self.name = "ServerThread ({})".format(repr(address)) + super(ServerThread, self).__init__( + "ServerThread ({})".format(repr(address)) + ) def run(self): self.server.serve_forever() diff --git a/mitmproxy/main.py b/mitmproxy/main.py index 34d4aa6b..53417fe8 100644 --- a/mitmproxy/main.py +++ b/mitmproxy/main.py @@ -47,6 +47,7 @@ def process_options(parser, options): sys.exit(0) if options.quiet: options.verbose = 0 + debug.register_info_dumper() return config.process_proxy_options(parser, options) diff --git a/mitmproxy/protocol/http2.py b/mitmproxy/protocol/http2.py index 9247e657..957b8d64 100644 --- a/mitmproxy/protocol/http2.py +++ b/mitmproxy/protocol/http2.py @@ -18,6 +18,7 @@ from mitmproxy.protocol import base from mitmproxy.protocol import http import netlib.http from netlib import tcp +from netlib import basethread from netlib.http import http2 @@ -261,10 +262,12 @@ class Http2Layer(base.Layer): self._cleanup_streams() -class Http2SingleStreamLayer(http._HttpTransmissionLayer, threading.Thread): +class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread): def __init__(self, ctx, stream_id, request_headers): - super(Http2SingleStreamLayer, self).__init__(ctx, name="Thread-Http2SingleStreamLayer-{}".format(stream_id)) + super(Http2SingleStreamLayer, self).__init__( + ctx, name="Http2SingleStreamLayer-{}".format(stream_id) + ) self.zombie = None self.client_stream_id = stream_id self.server_stream_id = None diff --git a/mitmproxy/protocol/http_replay.py b/mitmproxy/protocol/http_replay.py index 5928c0af..e804eba9 100644 --- a/mitmproxy/protocol/http_replay.py +++ b/mitmproxy/protocol/http_replay.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, print_function, division -import threading import traceback import netlib.exceptions @@ -8,12 +7,13 @@ from mitmproxy import controller from mitmproxy import exceptions from mitmproxy import models from netlib.http import http1 +from netlib import basethread # TODO: Doesn't really belong into mitmproxy.protocol... -class RequestReplayThread(threading.Thread): +class RequestReplayThread(basethread.BaseThread): name = "RequestReplayThread" def __init__(self, config, flow, event_queue, should_exit): @@ -26,7 +26,9 @@ class RequestReplayThread(threading.Thread): self.channel = controller.Channel(event_queue, should_exit) else: self.channel = None - super(RequestReplayThread, self).__init__() + super(RequestReplayThread, self).__init__( + "RequestReplay (%s)" % flow.request.url + ) def run(self): r = self.flow.request diff --git a/mitmproxy/script/concurrent.py b/mitmproxy/script/concurrent.py index 89c835f6..56d39d0b 100644 --- a/mitmproxy/script/concurrent.py +++ b/mitmproxy/script/concurrent.py @@ -5,10 +5,10 @@ offload computations from mitmproxy's main master thread. from __future__ import absolute_import, print_function, division from mitmproxy import controller -import threading +from netlib import basethread -class ScriptThread(threading.Thread): +class ScriptThread(basethread.BaseThread): name = "ScriptThread" @@ -24,5 +24,8 @@ def concurrent(fn): if not obj.reply.acked: obj.reply.ack() obj.reply.take() - ScriptThread(target=run).start() + ScriptThread( + "script.concurrent (%s)" % fn.__name__, + target=run + ).start() return _concurrent |