Revert "termio/exec: fix SIGPIPE crash when reader exits early"

This reverts commit 3e24e96af51fe308705a1f1695e3b9045c54482e.
This commit is contained in:
Mitchell Hashimoto
2025-01-09 12:43:41 -08:00
parent 12ce9f2e3b
commit 6ef757a8f8

View File

@ -179,11 +179,8 @@ pub fn threadExit(self: *Exec, td: *termio.Termio.ThreadData) void {
// Quit our read thread after exiting the subprocess so that // Quit our read thread after exiting the subprocess so that
// we don't get stuck waiting for data to stop flowing if it is // we don't get stuck waiting for data to stop flowing if it is
// a particularly noisy process. // a particularly noisy process.
if (exec.read_thread_pipe) |pipe| { _ = posix.write(exec.read_thread_pipe, "x") catch |err|
posix.close(pipe); log.warn("error writing to read thread quit pipe err={}", .{err});
// Tell deinit that we've already closed the pipe
exec.read_thread_pipe = null;
}
if (comptime builtin.os.tag == .windows) { if (comptime builtin.os.tag == .windows) {
// Interrupt the blocking read so the thread can see the quit message // Interrupt the blocking read so the thread can see the quit message
@ -642,7 +639,7 @@ pub const ThreadData = struct {
/// Reader thread state /// Reader thread state
read_thread: std.Thread, read_thread: std.Thread,
read_thread_pipe: ?posix.fd_t, read_thread_pipe: posix.fd_t,
read_thread_fd: posix.fd_t, read_thread_fd: posix.fd_t,
/// The timer to detect termios state changes. /// The timer to detect termios state changes.
@ -655,8 +652,7 @@ pub const ThreadData = struct {
termios_mode: ptypkg.Mode = .{}, termios_mode: ptypkg.Mode = .{},
pub fn deinit(self: *ThreadData, alloc: Allocator) void { pub fn deinit(self: *ThreadData, alloc: Allocator) void {
// If the pipe isn't closed, close it. posix.close(self.read_thread_pipe);
if (self.read_thread_pipe) |pipe| posix.close(pipe);
// Clear our write pools. We know we aren't ever going to do // Clear our write pools. We know we aren't ever going to do
// any more IO since we stop our data stream below so we can just // any more IO since we stop our data stream below so we can just
@ -1437,12 +1433,9 @@ pub const ReadThread = struct {
}; };
// This happens on macOS instead of WouldBlock when the // This happens on macOS instead of WouldBlock when the
// child process dies. It's equivalent to NotOpenForReading // child process dies. To be safe, we just break the loop
// so we can just exit. // and let our poll happen.
if (n == 0) { if (n == 0) break;
log.info("io reader exiting", .{});
return;
}
// log.info("DATA: {d}", .{n}); // log.info("DATA: {d}", .{n});
@call(.always_inline, termio.Termio.processOutput, .{ io, buf[0..n] }); @call(.always_inline, termio.Termio.processOutput, .{ io, buf[0..n] });
@ -1454,8 +1447,8 @@ pub const ReadThread = struct {
return; return;
}; };
// If our quit fd is closed, we're done. // If our quit fd is set, we're done.
if (pollfds[1].revents & posix.POLL.HUP != 0) { if (pollfds[1].revents & posix.POLL.IN != 0) {
log.info("read thread got quit signal", .{}); log.info("read thread got quit signal", .{});
return; return;
} }