@@ -179,11 +179,8 @@ pub fn threadExit(self: *Exec, td: *termio.Termio.ThreadData) void {
179
179
// Quit our read thread after exiting the subprocess so that
180
180
// we don't get stuck waiting for data to stop flowing if it is
181
181
// a particularly noisy process.
182
- if (exec .read_thread_pipe ) | pipe | {
183
- posix .close (pipe );
184
- // Tell deinit that we've already closed the pipe
185
- exec .read_thread_pipe = null ;
186
- }
182
+ _ = posix .write (exec .read_thread_pipe , "x" ) catch | err |
183
+ log .warn ("error writing to read thread quit pipe err={}" , .{err });
187
184
188
185
if (comptime builtin .os .tag == .windows ) {
189
186
// Interrupt the blocking read so the thread can see the quit message
@@ -642,7 +639,7 @@ pub const ThreadData = struct {
642
639
643
640
/// Reader thread state
644
641
read_thread : std.Thread ,
645
- read_thread_pipe : ? posix.fd_t ,
642
+ read_thread_pipe : posix.fd_t ,
646
643
read_thread_fd : posix.fd_t ,
647
644
648
645
/// The timer to detect termios state changes.
@@ -655,8 +652,7 @@ pub const ThreadData = struct {
655
652
termios_mode : ptypkg.Mode = .{},
656
653
657
654
pub fn deinit (self : * ThreadData , alloc : Allocator ) void {
658
- // If the pipe isn't closed, close it.
659
- if (self .read_thread_pipe ) | pipe | posix .close (pipe );
655
+ posix .close (self .read_thread_pipe );
660
656
661
657
// Clear our write pools. We know we aren't ever going to do
662
658
// any more IO since we stop our data stream below so we can just
@@ -1437,12 +1433,9 @@ pub const ReadThread = struct {
1437
1433
};
1438
1434
1439
1435
// This happens on macOS instead of WouldBlock when the
1440
- // child process dies. It's equivalent to NotOpenForReading
1441
- // so we can just exit.
1442
- if (n == 0 ) {
1443
- log .info ("io reader exiting" , .{});
1444
- return ;
1445
- }
1436
+ // child process dies. To be safe, we just break the loop
1437
+ // and let our poll happen.
1438
+ if (n == 0 ) break ;
1446
1439
1447
1440
// log.info("DATA: {d}", .{n});
1448
1441
@call (.always_inline , termio .Termio .processOutput , .{ io , buf [0.. n ] });
@@ -1454,8 +1447,8 @@ pub const ReadThread = struct {
1454
1447
return ;
1455
1448
};
1456
1449
1457
- // If our quit fd is closed , we're done.
1458
- if (pollfds [1 ].revents & posix .POLL .HUP != 0 ) {
1450
+ // If our quit fd is set , we're done.
1451
+ if (pollfds [1 ].revents & posix .POLL .IN != 0 ) {
1459
1452
log .info ("read thread got quit signal" , .{});
1460
1453
return ;
1461
1454
}
0 commit comments