Repository navigation
Description
Problem Description
When an addon sets ignore_connection = True in the tls_clienthello hook on a QUIC
connection, the connection stalls immediately and mitmproxy raises
AssertionError: Unexpected event type at UDPLayer.start: Expected Start, got DataReceived(client, ...)
Nothing is relayed in either direction: the client handshake never completes and the
target server receives no datagrams at all. ignore_connection is documented on
tls.ClientHelloData as the supported way for an addon to pass a connection through
untouched, and it works for TLS-over-TCP; only the QUIC path is affected.
ClientQuicLayer.receive_handshake_data swaps the QUIC layers for an ignored UDPLayer
and patches the parent layer's dispatch, but neither of the two assignments it makes
survives:
parent_layer._handle_event = replacement_layer._handle_eventcaptures a bound method
while the UDP layer is still in itsstartstate.UDPLayer.startlater sets
self._handle_event = self.relay_messageson the replacement layer, which the parent
never re-reads, so the parent stays pinned tostartforever.parent_layer.handle_event = replacement_layer.handle_eventcannot compensate, because
an outer layer may already hold a bound reference to the original.NextLayer._ask
caches exactly that asNextLayer._handlewhen it decides the layer stack, which happens
on the first datagram — before the ClientHello is parsed. Events keep arriving through
the cached method, find the parent unpaused, and dispatch into the frozenstartstate.
There is a second, related failure in the same swap: a command issued before the swap by
one of the replaced layers can still be in flight, and its reply is routed to the parent,
which now dispatches it into the ignored UDP layer. RawQuicLayer(force_raw=True) builds a
datagram UDPLayer in its constructor, so --mode reverse:quic:// reliably has an
outstanding UdpStartHook when the ClientHello arrives, and the very first assertion in the
reproduction below is got Reply(UdpStartHook(flow=<UDPFlow (0 messages)>), None).
This is not a race and does not depend on connection_strategy. It fires on the first
post-ClientHello event whether the server connection is already open or not, and the
OpenConnectionCompleted reply is misdelivered the same way — it is replacement_layer
that holds _paused while the event reaches parent_layer.
Steps to reproduce the behavior:
-
Save this addon as
passthrough_addon.py:from mitmproxy import tls def tls_clienthello(data: tls.ClientHelloData) -> None: data.ignore_connection = True
-
Start any QUIC server on
127.0.0.1:14443(I used a ~25-lineaioquicecho server that
uppercases whatever arrives on a stream), then run mitmproxy in front of it:mitmdump --mode reverse:quic://127.0.0.1:14443@14444 -s passthrough_addon.py -
Connect a QUIC client to
localhost:14444and send one stream message.
Expected: the datagrams are relayed unmodified in both directions and the client gets its
echo back, as it does when mitmproxy is taken out of the path.
Actual: the client fails with ConnectionError (the handshake never completes), the target
server logs nothing, and mitmdump prints "mitmproxy has crashed!" nine times, starting with:
[..] client connect
[..] addon: ignoring connection, sni=localhost
[..] mitmproxy has crashed!
Traceback (most recent call last):
File "mitmproxy/proxy/server.py", line 390, in server_event
for command in layer_commands:
File "mitmproxy/proxy/layer.py", line 157, in handle_event
command = command_generator.send(send)
File "mitmproxy/proxy/layer.py", line 270, in handle_event
yield from self._handle(event)
File "mitmproxy/proxy/layer.py", line 148, in handle_event
command_generator = self._handle_event(event)
File "mitmproxy/proxy/utils.py", line 27, in _check_event_type
raise AssertionError(
AssertionError: Unexpected event type at UDPLayer.start: Expected Start, got Reply(UdpStartHook(flow=<UDPFlow (0 messages)>), None).
followed by one per client datagram (got DataReceived(client, b'\xc9\x00\x00\x00\x01...'))
and finally two for the ConnectionClosed events. Note layer.py:270 in every trace: that
is NextLayer.handle_event dispatching through its cached _handle, which is what makes
the handle_event reassignment ineffective.
I originally hit this on Android, where an analysis sandbox uses ignore_connection for
passive (no-decryption) capture: guest apps emitted only outbound QUIC Initials, got no
inbound datagrams, and Cronet fell back to HTTP/2. The reproduction above is that scenario
reduced to stock mitmproxy with no Android involved.
I have a fix with regression tests ready and will open a PR right after this issue.
System Information
Mitmproxy: 12.2.3
Python: 3.13.14
OpenSSL: OpenSSL 4.0.1 9 Jun 2026
Platform: macOS-26.6-arm64-arm-64bit-Mach-O
Also reproduced on main (c69122b); mitmproxy/proxy/layers/quic/_stream_layers.py is
unchanged between 12.2.3 and main.
Checklist
- This bug affects the latest mitmproxy release.
Activity
kasnder commentedon Jul 29, 2026
Fix with regression tests: #8339