fix(src/client.zig): tolerate input writes racing the detach#38
Merged
Conversation
Between the daemon detaching a client (closing its connection) and the client reading the queued detached message, forwarded input can hit a closed socket. The write failed with EPIPE and attach treated it as fatal, printing 'error: BrokenPipe' and exiting nonzero instead of completing the detach; a held detach key makes the window easy to hit, and CI caught it on the new leak tests. Stop forwarding on a failed input write and let the queued lifecycle message, or the socket EOF, decide the outcome.
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.
Follow-up to #36, caught by its new leak tests in the v0.5.12 release PR CI (#37).
Root cause
Between the daemon detaching a client (which closes its end of the connection) and the client reading the queued
detachedmessage, the client can still forward terminal input. That write hits a closed socket, fails withEPIPE, andattachtreated it as fatal: boo printederror: BrokenPipeand exited nonzero instead of completing the clean detach. A held detach key (auto-repeats arriving during the round trip) makes the window easy to hit; theheld C-a C-dintegration test tripped it on a slow runner.Fix
A failed
.inputwrite stops stdin forwarding instead of aborting; the loop keeps reading the socket, where the queued lifecycle message (or EOF, yieldinglost) decides the outcome.Validation
zig build test-integrationrun 5 consecutive times clean (the race previously surfaced under repeat-heavy input from the new leak tests).zig build test-allandzig fmt --checkpass.This PR was generated by Coder Agents on behalf of @kylecarbs.