Skip to content

Make per-address connection concurrency limit configurable - #8323

Open
alt-efi wants to merge 2 commits into
mitmproxy:mainfrom
alt-efi:connection-max-per-address-option
Open

alt-efi wants to merge 2 commits into
mitmproxy:mainfrom
alt-efi:connection-max-per-address-option

Conversation

@alt-efi

@alt-efi alt-efi commented Jul 13, 2026

Copy link
Copy Markdown

Fixes #8322

Summary

ConnectionHandler.__init__ hardcoded asyncio.Semaphore(5) as the concurrency cap for connections to any single destination address, held for the connection's entire lifetime (open_connection() wraps handle_connection() inside the async with self.max_conns[address]: block). There was no Options field or --set flag for this value anywhere — a 6th concurrent connection to the same address just queues indefinitely behind whichever of the 5 stays open longest.

This adds connection_max_per_address (default 5, so behavior is unchanged unless a user opts in) and reads it in ConnectionHandler.__init__ instead of the hardcoded literal.

Changes

  • mitmproxy/options.py: new connection_max_per_address option, default 5.
  • mitmproxy/proxy/server.py: ConnectionHandler.__init__ reads the option instead of the hardcoded 5.
  • test/mitmproxy/proxy/test_server.py: two new tests asserting the behavior (the Nth+1 connection actually blocks / doesn't block) via the public Semaphore API (acquire/locked), not by inspecting private state. One pins the existing default-5 behavior, the other confirms a custom connection_max_per_address is honored.

Testing

  • pytest test/mitmproxy/proxy/test_server.py test/mitmproxy/test_options.py — all pass.
  • ruff check / ruff format --check / mypy on the changed files — all clean.

alt-efi and others added 2 commits July 13, 2026 17:54
ConnectionHandler hardcoded a limit of 5 concurrent connections to any
single destination address, with no way to change it. Add
connection_max_per_address (default 5, preserving current behavior) so
tools that legitimately need more concurrency to one host can raise it.

Fixes mitmproxy#8322

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.

ConnectionHandler's per-destination connection concurrency (asyncio.Semaphore(5)) is hardcoded with no way to configure it

1 participant