termio/exec: if pty fd HUP, end read thread (#5351)
Fixes #4884 When our command exits, it will close the pty slave fd. This will trigger a HUP on our poll. Previously, we only checked for IN. When a fd is closed, IN triggers forever which would leave to an infinite loop and 100% CPU. Now, detect the HUP and exit the read thread.pull/5353/head
commit
69dcea5148
|
|
@ -179,8 +179,17 @@ pub fn threadExit(self: *Exec, td: *termio.Termio.ThreadData) void {
|
|||
// Quit our read thread after exiting the subprocess so that
|
||||
// we don't get stuck waiting for data to stop flowing if it is
|
||||
// a particularly noisy process.
|
||||
_ = posix.write(exec.read_thread_pipe, "x") catch |err|
|
||||
log.warn("error writing to read thread quit pipe err={}", .{err});
|
||||
_ = posix.write(exec.read_thread_pipe, "x") catch |err| switch (err) {
|
||||
// BrokenPipe means that our read thread is closed already,
|
||||
// which is completely fine since that is what we were trying
|
||||
// to achieve.
|
||||
error.BrokenPipe => {},
|
||||
|
||||
else => log.warn(
|
||||
"error writing to read thread quit pipe err={}",
|
||||
.{err},
|
||||
),
|
||||
};
|
||||
|
||||
if (comptime builtin.os.tag == .windows) {
|
||||
// Interrupt the blocking read so the thread can see the quit message
|
||||
|
|
@ -1467,6 +1476,13 @@ pub const ReadThread = struct {
|
|||
log.info("read thread got quit signal", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
// If our pty fd is closed, then we're also done with our
|
||||
// read thread.
|
||||
if (pollfds[0].revents & posix.POLL.HUP != 0) {
|
||||
log.info("pty fd closed, read thread exiting", .{});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue