From 4eb6252d35abba437ac672cc20025b75bef8f217 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 05:54:59 -0300 Subject: remote client: a link's end read before the drain, not after it: the link reader posts `link_gone` just before it marks its end, so a drain that tested the mark last could leave that post queued, and the next link (a rejoin after divergence or an Upgrade) took it and ended at once, the client saying 'let this client go' right after 'joined again' (test/daemon.py's forced divergence, about one run in ten under load) Co-Authored-By: Claude Opus 5.5 --- src/tty/tty.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/tty/tty.zig') diff --git a/src/tty/tty.zig b/src/tty/tty.zig index 08964d73..994ebd92 100644 --- a/src/tty/tty.zig +++ b/src/tty/tty.zig @@ -1585,15 +1585,18 @@ pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, se if (init.environ_map.get("PARDES_REPLICA_STATS")) |file| link.writeStats(file); if (!link.gone) replica.bye(joined.fd); // The link's reader ends with the link, posting as it goes: what it - // and the terminal posted is let go until it has. + // and the terminal posted is let go until it has. Its end is read + // before the drain, not after: its last post (`link_gone`) comes + // just before it, and left queued it ended the next link at once. _ = libc.shutdown(joined.fd, 2); while (true) { + const ended = reader_done.load(.acquire); while (loop.tryEvent() catch null) |ev| switch (ev) { .unit, .screen, .refused => |b| std.heap.c_allocator.free(b), .paste => |b| gpa.free(@constCast(b)), else => {}, }; - if (reader_done.load(.acquire)) break; + if (ended) break; std.Thread.yield() catch {}; } reader.join(); -- cgit v1.3