szn

Bug 402 — Display out-queue atomicity

402. Display out-queue atomicity: header and body queued separately, frame build clears queued replies, detach packet freed before flush (#374/#376 class regression)

Severity: HIGH Status: ✅ RESOLVED

Three sites treat a non-atomic queue as atomic:

  1. Split frame enqueue — header (5 bytes) and body are queued in two calls (:2313-2315; :3127-3128). If the client flips to behind or an appendSlice fails (catch continue at :3128) between them, the header reaches the wire without its body. The client’s stream parser then consumes the next frame’s bytes as the missing body — display garbled until a .redraw.
  2. Queue wipe — dc.out_buf.clearRetainingCapacity() (:3126) before the frame discards anything queued since the last flush, including urgent command replies — the exact guarantee bug #376 documents (:2660-2663).
  3. Detach packet loss — the .detach action queues the detach packet (:1113) and one statement later dc.deinit(self.allocator) (:1120) frees out_buf. On EAGAIN the packet never leaves; the client stays “attached” to a server that stopped rendering to it — the silent-truncation failure the code comment at :1107-1109 says bug #374 fixed.

Fix: enqueue header+body as one operation (append both to a scratch, queue once); never clearRetainingCapacity while a reply backlog exists; for detach, keep the DisplayClient alive until the buffer flushes (or close the fd so the client sees EOF).