From 1e9707307815144a3106c3b5056111971ad07c6d Mon Sep 17 00:00:00 2001 From: PavelICS <45364791+PavelICS@users.noreply.github.com> Date: Mon, 10 Jan 2022 17:58:14 +0300 Subject: [PATCH] Fix crush shutdown when MITM has it's own loop (#5042) When I call shutdown with a different loop in the current thread from MITM loop, it's crashes with the error: `ValueError: The future belongs to a different loop than the one specified as the loop argument` Setting a loop explicit fixes the problem. --- mitmproxy/master.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 888406ae7..ac69d5278 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -92,7 +92,7 @@ class Master: # This all needs to be simplified when the proxy server runs on asyncio as well. if not self.event_loop.is_running(): # pragma: no cover try: - self.event_loop.run_until_complete(asyncio.wrap_future(ret)) + self.event_loop.run_until_complete(asyncio.wrap_future(ret, loop=self.event_loop)) except RuntimeError: pass # Event loop stopped before Future completed.