From 8396244729f67ab5ca3c750b280aef2bc0b34006 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 18 Apr 2018 08:21:08 +1200 Subject: [PATCH 1/3] mitmweb: shift to use new run_loop wrapper on master Fixes #3067 --- mitmproxy/tools/web/master.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/mitmproxy/tools/web/master.py b/mitmproxy/tools/web/master.py index 575694c73..e2c60d94e 100644 --- a/mitmproxy/tools/web/master.py +++ b/mitmproxy/tools/web/master.py @@ -105,33 +105,21 @@ class WebMaster(master.Master): def run(self): # pragma: no cover AsyncIOMainLoop().install() - iol = tornado.ioloop.IOLoop.instance() - http_server = tornado.httpserver.HTTPServer(self.app) http_server.listen(self.options.web_port, self.options.web_iface) - - iol.add_callback(self.start) - web_url = "http://{}:{}/".format(self.options.web_iface, self.options.web_port) self.log.info( "Web server listening at {}".format(web_url), ) - + # FIXME: This should be in an addon hooked to the "running" event, not in master if self.options.web_open_browser: success = open_browser(web_url) if not success: self.log.info( "No web browser found. Please open a browser and point it to {}".format(web_url), ) - try: - iol.start() - except KeyboardInterrupt: - self.shutdown() - - def shutdown(self): - tornado.ioloop.IOLoop.instance().stop() - super().shutdown() + self.run_loop(iol.start) def open_browser(url: str) -> bool: From bca0275427e5879e49cd91d0802e51052a8000d1 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 18 Apr 2018 08:22:26 +1200 Subject: [PATCH 2/3] tcp: As of Python 3.5, EINTR is retried automatically by select See https://www.python.org/dev/peps/pep-0475/ --- mitmproxy/net/tcp.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py index b842f11f2..5e53e398f 100644 --- a/mitmproxy/net/tcp.py +++ b/mitmproxy/net/tcp.py @@ -22,8 +22,6 @@ socket_fileobject = socket.SocketIO # Python 3.6 for Windows is missing a constant IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41) -EINTR = 4 - class _FileLike: BLOCKSIZE = 1024 * 32 @@ -595,14 +593,7 @@ class TCPServer: self.__is_shut_down.clear() try: while not self.__shutdown_request: - 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 + r, w_, e_ = select.select([self.socket], [], [], poll_interval) if self.socket in r: connection, client_address = self.socket.accept() t = basethread.BaseThread( From e6538cdb1f757e544a20c24c35259e0bbea212ab Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 18 Apr 2018 08:35:07 +1200 Subject: [PATCH 3/3] mitmweb: don't blort all over my config file Temporarily disable config saving until we can look at this more closely. Config saving should: - Only happen when explicitly requested by the user - Only save changed values --- mitmproxy/tools/web/app.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index 936eb75b0..61e30a213 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -18,7 +18,6 @@ from mitmproxy import io from mitmproxy import log from mitmproxy import version from mitmproxy import optmanager -from mitmproxy.tools.cmdline import CONFIG_PATH import mitmproxy.tools.web.master # noqa @@ -457,10 +456,11 @@ class Options(RequestHandler): class SaveOptions(RequestHandler): def post(self): - try: - optmanager.save(self.master.options, CONFIG_PATH, True) - except Exception as err: - raise APIError(400, "{}".format(err)) + # try: + # optmanager.save(self.master.options, CONFIG_PATH, True) + # except Exception as err: + # raise APIError(400, "{}".format(err)) + pass class Application(tornado.web.Application):