os/open: stderr reader thread spins at 100% CPU forever once the opener writes a newline (takeDelimiterExclusive never consumes the delimiter) #14100
Summary
Present in current MechanicsZig 0.16 pub fn takeDelimiterExclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
const result = try r.peekDelimiterExclusive(delimiter); // strips the trailing '\n' from the slice
r.toss(result.len); // tosses only the EXCLUSIVE length
return result;
}So for buffered stderr
Observed impactmacOS app embedding libghostty, several days of uptime: six leaked opener threads (six link clicks whose
ReproductionAny platform where the opener writes at least one newline to stderr. On macOS: Then watch one CPU core disappear and Suggested fixConsume the delimiter — e.g. read inclusively and trim for logging: while (true) {
const line = reader.takeDelimiterInclusive('\n') catch |outer| switch (outer) {
error.EndOfStream => break,
error.ReadFailed => break,
error.StreamTooLong => reader.take(buffer.len) catch |inner| switch (inner) {
error.ReadFailed => break,
error.EndOfStream => break,
},
};
log.warn("open stderr={s}", .{std.mem.trimEnd(u8, line, "\n")});
}( |
Replies: 2 comments
|
!vouch |
|
fyi i think these two were interrelated when i first reported: hit that combo bug again in 1.3.2 today. was the OSC issue addressed separately? |
!vouch