fix(start_proxy): fail fast on bind error instead of false "Started" - #24
Open
felipetruman wants to merge 1 commit into
Open
fix(start_proxy): fail fast on bind error instead of false "Started"#24felipetruman wants to merge 1 commit into
felipetruman wants to merge 1 commit into
Conversation
start() scheduled master.run() via create_task and immediately returned
"Started proxy on port N" + set running=True, without waiting for the bind.
When the port was already in use, mitmproxy's master.run() died
asynchronously with SystemExit(1) ("address already in use"), leaving the
controller in a false state: running=True but no proxy listening, plus an
unretrieved task exception polluting the event loop.
Add a synchronous probe bind before starting the master. If the port is
taken, return a clear error and leave running=False. Deterministic and
avoids chasing mitmproxy's async SystemExit.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MitmController.start()schedulesmaster.run()viaasyncio.create_taskand immediately returns"Started proxy on port N"while settingrunning = True— without waiting for the bind to succeed.When the port is already in use, mitmproxy's
master.run()dies asynchronously withSystemExit(1)(address already in use). The result is a false state:start_proxyreports success to the callerrunning == Truebut no proxy is actually listeningTask exception was never retrieved)Fix
Add a synchronous probe
bind()before launching the master. If the port is taken, return a clear error and leaverunning=False. Deterministic — avoids trying to catch mitmproxy's asyncSystemExit.Verification
"Started proxy on port N", proxy listens,stop()works (unchanged)."Couldn't start the proxy on 127.0.0.1:8097: [Errno 98] Address already in use",running=False, no orphan task exception.🤖 Generated with Claude Code