diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index e41b27849..c438776dd 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -60,7 +60,9 @@ pub fn Stream(comptime Handler: type) type { for (actions) |action_opt| { const action = action_opt orelse continue; - // log.info("action: {}", .{action}); + // if (action != .print) { + // log.info("action: {}", .{action}); + // } // If this handler handles everything manually then we do nothing // if it can be processed. diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 7a409e8f7..a4a3e4eb1 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1398,7 +1398,21 @@ const StreamHandler = struct { } inline fn messageWriter(self: *StreamHandler, msg: termio.Message) void { - _ = self.ev.writer_mailbox.push(msg, .{ .forever = {} }); + // Try to write to the mailbox with an instant timeout. If the + // mailbox is full, then we wake up the writer thread mid-processing + // so it can process the message and then try again with a forever + // wait. + if (self.ev.writer_mailbox.push(msg, .{ .instant = {} }) == 0) { + self.ev.writer_wakeup.notify() catch |err| { + log.warn("failed to wake up writer, data will be dropped err={}", .{err}); + return; + }; + + _ = self.ev.writer_mailbox.push(msg, .{ .forever = {} }); + } + + // Normally, we just flag this true to wake up the writer thread + // once per batch of data. self.writer_messaged = true; }