From fb7e632248c599a70689cd0451392c8a890044ee Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 15:13:48 -0300 Subject: daemon: the reader hands no note to a session loop that ended: it took the loop's address once, at its start, and ran on until main's daemon.quit joined it, after Loop.run returned, so a client connecting (or a shell adopted, or a daemon relinked) while a session ended was handed to the loop's dead frame (l.peers, l.inbox, deinit'ed); now the reader hands each note under a lock to where notesTo says (daemon.give), the session loop sets it after its frontend opened and clears it (notesTo(null)) before its peers, frontend and queue go, and a note with nowhere to go is let go, its connections closed; test "a client's connection the daemon hands on after the session's loop ended reaches no loop: it is closed" (a fake daemon on a socketpair link): "expected 0, found 1" (the ended loop handed it) on the base, passes now; a user could hit it: a pardes attach (or Adopt's answer) in the moment its session exits: a write into a dead stack frame (a crash or a corrupted teardown) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/session.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'runtime/session.zig') diff --git a/runtime/session.zig b/runtime/session.zig index 9c8446e3..a0c27799 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -101,10 +101,13 @@ pub fn Loop(comptime Frontend: type) type { l.host = try fe.open(&l); defer fe.close(&l); - daemon.notesTo(&l, note); defer l.peers.deinit(); // Before the core goes: each client sees its link end. defer l.peers.dropAll(l.core); + // The daemon's notes, to the loop until its state goes (the + // reader runs on until main's `daemon.quit`). + daemon.notesTo(.{ .ctx = &l, .deliver = note }); + defer daemon.notesTo(null); // A first client on the socket it was started with, before its // first effects: it has every terminal from its first byte, and // no reload (Core.openView). -- cgit v1.3