Skip to content

fix(src/client.zig): tolerate input writes racing the detach#38

Merged
kylecarbs merged 1 commit into
mainfrom
fix/attach-input-write-race
Jun 11, 2026
Merged

fix(src/client.zig): tolerate input writes racing the detach#38
kylecarbs merged 1 commit into
mainfrom
fix/attach-input-write-race

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

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 detached message, the client can still forward terminal input. That write hits a closed socket, fails with EPIPE, and attach treated it as fatal: boo printed error: BrokenPipe and 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; the held C-a C-d integration test tripped it on a slow runner.

Fix

A failed .input write stops stdin forwarding instead of aborting; the loop keeps reading the socket, where the queued lifecycle message (or EOF, yielding lost) decides the outcome.

Validation

  • zig build test-integration run 5 consecutive times clean (the race previously surfaced under repeat-heavy input from the new leak tests).
  • zig build test-all and zig fmt --check pass.

This PR was generated by Coder Agents on behalf of @kylecarbs.

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.
@kylecarbs kylecarbs merged commit 2916fbd into main Jun 11, 2026
4 checks passed
@kylecarbs kylecarbs mentioned this pull request Jun 11, 2026
@kylecarbs kylecarbs deleted the fix/attach-input-write-race branch June 11, 2026 20:44
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.

1 participant