Skip to content

fix(macos): close UDP ConnectionTask on redirector EOF - #326

Open
BetterAndBetterII wants to merge 1 commit into
mitmproxy:mainfrom
BetterAndBetterII:fix/macos-udp-eof-leak
Open

fix(macos): close UDP ConnectionTask on redirector EOF#326
BetterAndBetterII wants to merge 1 commit into
mitmproxy:mainfrom
BetterAndBetterII:fix/macos-udp-eof-leak

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

In macOS local redirect mode, ConnectionTask::handle_udp used Some(packet) = stream.next(), so redirector EOF (None) disabled that select! arm. When a UDP flow ended before its first datagram, ConnectionEstablished was never sent, Python never sent CloseConnection, and the UnixStream leaked for the process lifetime (EMFILE under DNS-heavy traffic).

Treat stream EOF like CloseConnection: state.close(); break; so the task drops the socket.

Fixes mitmproxy/mitmproxy#8412 (UDP counterpart of the TCP leak class fixed in #260 / mitmproxy#7675).

Test plan

  • cargo test -p mitmproxy --lib packet_sources::macos::tests
    • udp_eof_before_first_datagram_completes (timed out before fix)
    • udp_eof_after_first_datagram_completes (timed out before fix)
  • macOS local-mode smoke: DNS-heavy traffic no longer climbs unix fds without bound

Some(packet) = stream.next() ignored None, so UDP flows closed before the
first datagram never got ConnectionEstablished/CloseConnection and leaked
the UnixStream forever (EMFILE under DNS-heavy local redirect).

Treat stream EOF like CloseConnection: state.close(); break.
Regression tests cover EOF before and after the first datagram.

Fixes mitmproxy/mitmproxy#8412
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.

macOS local mode: UDP flows closed by the redirector before their first datagram leak a file descriptor forever

1 participant