Skip to content

macos: don't block on stale TCP readiness - #327

Merged
mhils merged 1 commit into
mitmproxy:mainfrom
natefinch:macos-tcp-readiness
Sep 30, 2026
Merged

mhils merged 1 commit into
mitmproxy:mainfrom
natefinch:macos-tcp-readiness

Conversation

@natefinch

Copy link
Copy Markdown
Contributor

In the macOS redirector's TCP loop, writable()/readable() can report stale readiness, and the following write_buf().await/read_buf().await then blocks the whole select!. A pending read can stall writes (e.g. HTTP/2 responses), and a full write buffer can stall reads and shutdown.

This switches to try_write/try_read_buf and goes back to select! on WouldBlock. Includes regression tests for both directions.

Note: #326 adds a tests module to the same file, so whichever lands second needs a trivial rebase.

`writable()`/`readable()` can report stale readiness. Awaiting `write_buf`/`read_buf`
afterwards blocks the connection loop, so a pending read can stall writes and a full
write buffer can stall reads and shutdown. Use `try_write`/`try_read_buf` instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0822dee1-89da-4338-994f-bf1a11052c0e

@mhils mhils left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thank you! 🍰

@mhils
mhils enabled auto-merge (squash) September 30, 2026 22:50
@mhils
mhils merged commit 823ab2a into mitmproxy:main Sep 30, 2026
23 checks passed
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.

2 participants