Skip to content

Close the cached local redirector on final shutdown - #8459

Open
natefinch wants to merge 5 commits into
mitmproxy:mainfrom
natefinch:close-local-redirector-on-exit
Open

natefinch wants to merge 5 commits into
mitmproxy:mainfrom
natefinch:close-local-redirector-on-exit

Conversation

@natefinch

@natefinch natefinch commented Oct 1, 2026 •

Copy link
Copy Markdown

Description

Local mode deliberately keeps its native redirector cached when capture stops, to avoid repeated permission prompts. But the cached server is never explicitly closed on final shutdown. Its Rust tasks invoke Python callbacks and logging, so they should finish before interpreter teardown rather than relying on destruction during teardown.

On final shutdown, cancel and await pending mode updates, close listeners, and await the cached redirector before frontend/addon teardown. Preserve capture stop/start reuse, retain listener ownership when a mode change is interrupted, and shield cleanup from further cancellation. Cleanup also runs during interrupted startup, without tearing down an uninitialized console UI; shutdown failures propagate instead of being swallowed by addon hooks.

Complements mitmproxy/mitmproxy_rs#329, which joins native connection handlers when the server shuts down.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

natefinch and others added 4 commits October 1, 2026 11:27
Keep the redirector reusable when capture stops, but close and await its native tasks before interpreter teardown. Run cleanup on interrupted startup too, after cancelling and joining the Python startup tasks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0822dee1-89da-4338-994f-bf1a11052c0e
Only invoke Master.done() after running() has been called. On earlier shutdown, clean up the proxy directly so cached native tasks still finish without invoking uninitialized console UI teardown.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0822dee1-89da-4338-994f-bf1a11052c0e
Run explicit proxy shutdown before frontend and addon teardown. Shield cleanup from repeated cancellation, join pending mode updates, and preserve listener ownership when mode changes are interrupted. Avoid creating unowned startup coroutines before notifications, release cancelled redirector startup reservations, and propagate shutdown failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0822dee1-89da-4338-994f-bf1a11052c0e
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cfacfee1-d3e5-4b4d-9b9f-2712008a29e6

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant