mitmproxy doesn't exit without connection to web UI
Problem Description
Mitmproxy doesn't exit on Ctrl-C inside commond line without connection to web UI
Steps to reproduce the behavior:
- Run
mitmweb - Close tab or window which was open to visit http://127.0.0.1:8081/
- Press
Ctrl - Cin terminal - Nothing happens
- Open http://127.0.0.1:8081/ in browser
- It exists
System Information
Mitmproxy: 10.4.2
Python: 3.11.9
OpenSSL: LibreSSL 3.9.0
Platform: OpenBSD-7.6-amd64-64bit-ELF
This issue is likely specific to (Open)BSD. At least I can't reproduce it on Linux and macOS.
@mhils quite probably. Special that I had worked on port for OpenBSD for mitmproxy for a few moths, and this was imported last week.
Any suggestion how can I debug it future to provide some useful traces?
Here's our SIGTERM handling: https://github.com/mitmproxy/mitmproxy/blob/332f222994deb27bb0ab68618b23f270b3bdfe2d/mitmproxy/tools/main.py#L116-L128
I would assume the handler is never called?
What happens when you --no-web-open-browser? My guess is that's a focus issue with the terminal and you need to manually click into it or something.
@Prinzhorn when I run mitmweb --no-web-open-browser it indeed doesn't open web browser, and it ignores Ctrl - C. But if I go to http://127.0.0.1:8081/ after I had pressed C-c, it exists. Without visiting the web UI it stucks.
@mhils yeah, signal never fire the callback. But if I use loop.add_signal_handler it works like a charm.
Thanks! Do you want to send a patch that tries loop.add_signal_handler first and then falls back to signal.signal on exception? :)
@mhils here it is: https://github.com/mitmproxy/mitmproxy/pull/7130
Feel free to push into branch anything, if you think that I had missed it.