Skip to content

Make per-destination connection concurrency limit configurable - #8414

Open
jankesec wants to merge 2 commits into
mitmproxy:mainfrom
jankesec:fix/configurable-per-destination-connection-concurrency
Open

jankesec wants to merge 2 commits into
mitmproxy:mainfrom
jankesec:fix/configurable-per-destination-connection-concurrency

Conversation

@jankesec

@jankesec jankesec commented Sep 1, 2026

Copy link
Copy Markdown

Summary

This PR makes ConnectionHandler's per-destination connection concurrency limit configurable via options, resolving #8322.

Background & Solution

Previously, ConnectionHandler.__init__ (mitmproxy/proxy/server.py) hardcoded a concurrency limit of 5 open connections per destination address:

self.max_conns = collections.defaultdict(lambda: asyncio.Semaphore(5))

Because open_connection() holds that semaphore slot for the connection's entire lifetime, high-concurrency environments or tools proxying multiple requests to a single destination address experienced blocking with no configuration option to raise the limit.

This change:

  1. Adds connection_max_per_address (int, default 5) to Options in mitmproxy/options.py.
  2. Updates ConnectionHandler.__init__ in mitmproxy/proxy/server.py to initialize self.max_conns using context.options.connection_max_per_address.
  3. Adds unit test coverage in test/mitmproxy/test_options.py.

Fixes #8322

jankesec and others added 2 commits September 1, 2026 11:44
Add `connection_max_per_address` option (default: 5) to Options and use it in
ConnectionHandler to configure per-destination concurrency semaphore.

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