szn

Bug 207 — Non-blocking display socket buffer truncation on EAGAIN — server event-loop spin (freeze + 100% CPU)

207. Non-blocking display socket buffer truncation on EAGAIN — server event-loop spin (freeze + 100% CPU)

File: src/server/server.zig:2152 Severity: HIGH Status: ✅ FIXED — updated flushDisplayClient to shift the remaining unwritten buffer bytes to the front using std.mem.copyForwards and adjust the length, instead of truncating the buffer length to the written bytes. Added unit test.

When a display client socket returned EAGAIN during a write (occurring frequently on macOS due to smaller default UNIX domain socket buffers under heavy child output like bat), flushDisplayClient incorrectly set the buffer’s length to the number of bytes written (dc.out_buf.items.len = off). This truncated and discarded all the remaining unwritten bytes, and if off was 0, set the length to 0. On the next event-loop tick, the server bypassed the queued buffer check, regenerated a new frame, hit EAGAIN again, truncated to 0, and entered an infinite 100% CPU spin, freezing the tmux session.