Better error message for WireGuard port conflict
Problem Description
I have mitmweb configured to use the WireGuard mode. If I try to run 2 instances, the 2nd instance fails as expected because the port is already used. But the error message could be improved.
Steps to reproduce the behavior:
-
mitmweb --mode wireguardtwice
[12:23:18.282] Address already in use (os error 48)
Error logged during startup, exiting...
As a comparison, this is the error message you get when the web UI port conflicts:
Traceback (most recent call last):
File "mitmproxy/tools/web/master.py", line 111, in running
File "tornado/tcpserver.py", line 183, in listen
File "tornado/netutil.py", line 162, in bind_sockets
OSError: [Errno 48] Address already in use
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "mitmweb.py", line 4, in <module>
File "mitmproxy/tools/main.py", line 167, in mitmweb
File "mitmproxy/tools/main.py", line 137, in run
File "asyncio/runners.py", line 194, in run
File "asyncio/runners.py", line 118, in run
File "asyncio/base_events.py", line 720, in run_until_complete
File "mitmproxy/tools/main.py", line 134, in main
File "mitmproxy/master.py", line 84, in run
File "mitmproxy/tools/web/master.py", line 116, in running
OSError: [Errno 48] Web server failed to listen on 127.0.0.1:8081 with [Errno 48] Address already in use
Try specifying a different port by using `--set web_port=8083`.
[PYI-89638:ERROR] Failed to execute script 'mitmweb' due to unhandled exception!
System Information
Mitmproxy: 11.1.3 binary
Python: 3.13.1
OpenSSL: OpenSSL 3.4.1 11 Feb 2025
Platform: macOS-15.4-x86_64-64bit-Mach-O
Checklist
- [x] This bug affects the latest mitmproxy release.
~https://github.com/mitmproxy/mitmproxy/pull/7589 should fix this~
Hi. I've been checking this in my spare time. I think the problem is not from mitmproxy but mitmproxy_rs. The reason is that the first error is in the format of rust errors and the second one is the format of python errors. mitmproxy_rs seems to pass the error as an output instead of an exception. I will continue exploring. I'm not familiar yet with the code base.
I've opened a PR to address this: #7688 Feedback welcome!