Repository navigation
fly: copy stdin buffer before sending hijack input - #9668
Merged
Merged
Conversation
taylorsilva
approved these changes
Aug 3, 2026
taylorsilva
left a comment
Member
There was a problem hiding this comment.
LGTM - Thank you so much for fixing this! Was also one of those minor things I'd notice while busy troubleshooting something else and would forget about.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed by this PR
stdinWriter.Writehandedio.Copy's buffer straight to the channel thathandleInputserializes from.io.Copyreuses a single 32KB buffer, so the next read could overwrite bytes that hadn't been written to the websocket yet, and the JSON that went out held whatever was in the buffer at marshal time. Fixed by cloning the slice inWrite.stdinWriterrather than at the call site, sinceio.Writersays implementations must not retainp, so that's the side in the wrong.HijackInputframes match what was sent.Notes to reviewer
Typing never hits this because each read is one byte and the round trip finishes long before the next keystroke. Pasting does: the terminal delivers the payload in a burst, the reads come back to back, and the input can land in the container reordered and duplicated once the paste spans more than one read.
How often you see it depends on how your terminal feeds the pty. In my case, Ghostty and Alacritty on macOS push a paste in large writes with no gaps, which trips it easily. Terminals like iTerm that split a paste into smaller writes, or pace them (some rate limit paste input, and anything routing through tmux or ssh gets chunked along the way), leave enough time between reads for the previous frame to go out, so the corruption stays hidden. The race is there either way.
The fake ATC in the integration test sleeps for a second before reading input frames. That fills the socket buffers so fly's
WriteJSONblocks, which is what opens the race window. Without it the race is 50/50, causing it to pass against the broken code.To confirm: revert the
bytes.Cloneand the test fails on the byte comparison.Release Note
fly hijack/fly intercept. Pasted text longer than a single terminal read could arrive at the container reordered or duplicated.