szn

Bug 364 — remain-on-exit: closed pty master stays polled → NVAL spin

364. Missing removeFd + zero POLLNVAL handling

File: src/server/server.zig:789-794 (offending path), src/server/server.zig:828-830 (correct pattern) Severity: HIGH Status: ✅ FIXED

Fix (applied)

  1. The remain-on-exit path now calls self.loop.removeFd(pty.master) before pty.deinit(), mirroring destroyPane.
  2. Defence in depth: handlePtyEvent recognises POLLNVAL — drops the registration immediately and, when the pane’s own master matches, sets master = -1 before deinit() so nothing double-closes a possibly recycled fd number while still releasing input_buf and reaping the child.

Tests: pollOnce reports POLLNVAL for a closed registered fd — bug #364 (loop.zig, real kernel behaviour); handlePtyEvent drops registration on POLLNVAL — bug #364; remain-on-exit unregisters pty before closing master — bug #364 (pane survives with no live pty and no stale registration).

Problem

if (remain and has_other_panes) {
    if (pane.pty) |*pty| {
        pty.deinit();          // close(master) — fd still registered!
        pane.pty = null;
    }

The normal-exit path calls self.loop.removeFd(pty.master) first; this path does not. Next poll() reports POLLNVAL on the dead fd — and nothing in run()/handlePtyEvent checks NVAL (only IN/HUP/ERR are tested, server.zig:559-561, 673-677). Level-triggered NVAL on every iteration → permanent spin. Worse: if the fd number is recycled by another connection, events misroute to a stale udata pane pointer.

Fix (proposed)

Add self.loop.removeFd(pty.master) before pty.deinit() here, plus defense-in-depth: treat .NVAL like .HUP in the run loop and lazily drop the entry. Also see #365 for the killWindow twin.