Skip to content

Commit 34e93c0

Browse files
branchseerclaude
andcommitted
fix: close pty writer in read_to_end to eliminate race condition
On Linux, writing to a PTY master after the child exits can succeed (kernel buffers the data), unlike macOS which returns EIO. The background thread sets writer=None after setting exit_status, but read_to_end returns right after exit_status is set, creating a window where write() still succeeds. Close the writer in read_to_end itself. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 251c877 commit 34e93c0

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

crates/pty_terminal/src/terminal.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ impl Terminal {
194194
// Wait for exit status to be set by background thread
195195
let status = self.exit_status.wait().clone();
196196

197+
// Close the writer since the child has exited and all output has been consumed.
198+
// This ensures subsequent write() calls fail immediately, rather than racing
199+
// with the background thread which also closes the writer.
200+
*self.writer.lock().unwrap() = None;
201+
197202
Ok(status)
198203
}
199204

0 commit comments

Comments
 (0)