mitmproxy/mitmproxy

Better error message for WireGuard port conflict

Open

#7,650 opened on Apr 10, 2025

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Python (42,166 stars) (4,437 forks)batch import
area/corehelp wantedkind/ux

Description

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:

  1. mitmweb --mode wireguard twice
[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

Contributor guide