summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 05:49:21 -0300
committerGabriel Schneider <[email protected]>2026-11-21 06:21:57 -0300
commit744f1029ee2a02a43cb0fc70e32f70b60b100b75 (patch)
tree2c2ae2a7cb32b088c7785557914b73f6f4c0cf11 /core
parente29ff73bbb2c198afbb894ee98854da2d9a7be7d (diff)
downloadpardes-744f1029ee2a02a43cb0fc70e32f70b60b100b75.tar.gz
pardes-744f1029ee2a02a43cb0fc70e32f70b60b100b75.zip
client: a link an Upgrade's exec cuts with no last word joins again: `Peers.refuseAll` queues each client's `refused` after what it is still being sent and gives the writers 200 ms (`flushed200`), then `drop` cuts every link, so a client whose join's dump was still on its way read the cut as its session's end and exited 1 ("'NAME' let this client go"), with PARDES_PAIR or without (a `new --detach` session holding a 100 MB file, the Upgrade written as the attach is listed: 3 of 3 on main's ReleaseSafe build, 3 of 3 Debug); now a near link that ends with no last word asks this machine's daemon whether its session is listed still (`replica.cutListed`), and listed, joins again as one told `upgrading` (runtime/client.zig `Loop.run`; a first join cut mid-dump likewise, `replica.join`), so no flush bound decides a client's fate; a patient redial stops at once at "no session called" (`redial`: a session killed outright costs no 20 s of dialling); a far client and a no-daemon pair ask nobody (nothing changes); test/daemon.py `attach_upgrading` gains the round (two attaches to a 100 MB session, the Upgrade written as each joins; plain mode and --attach-upgrading): failed on merge48's builds, passes on both builds; tui core-test 885/1045 (160 skipped)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
-rw-r--r--core/replica.zig25
1 files changed, 23 insertions, 2 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 56fc4a59..edab01ee 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -3112,6 +3112,23 @@ pub fn ended(why: []const u8) bool {
/// What an Upgrade tells its clients (`Peers.refuseAll`): each dials again.
pub const upgrading = "the session is upgrading to another build of pardes";
+/// A near link cut with no last word (`why` its hang-up) whose session this
+/// machine's daemon lists still: an Upgrade's exec cut it, a dump on the
+/// way past the clients' flush (`Peers.refuseAll`), not the session's end,
+/// which the daemon sees as its link's: so the client joins again as one
+/// told `upgrading` does, whatever the flush's bound let through.
+pub fn cutListed(why: []const u8, session: []const u8) bool {
+ if (!std.mem.startsWith(u8, std.mem.sliceTo(why, 0), "the session hung up")) return false;
+ var buf: [8192]u8 = undefined;
+ const list = daemon.ask("list", &buf) orelse return false;
+ var lines = std.mem.tokenizeScalar(u8, list, '\n');
+ while (lines.next()) |line| {
+ if (!std.mem.startsWith(u8, line, "session ")) continue;
+ if (std.mem.eql(u8, line[(std.mem.lastIndexOfScalar(u8, line, ' ') orelse continue) + 1 ..], session)) return true;
+ }
+ return false;
+}
+
/// The words a client goes with when its session runs another build now.
const upgrade_words = "session upgraded to a newer pardes: upgrade this client too";
@@ -3151,8 +3168,9 @@ pub fn join(gpa: Allocator, j: *Joined, path: []const u8, session: []const u8, o
redial(gpa, path, session, why, have, true, v)
else
sameBuild(gpa, (dial(gpa, path, session, why, have, null) orelse
- // Handed to the session as it upgraded: it is there again soon.
- if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading)) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why)) orelse return null;
+ // Handed to the session as it upgraded, or cut by its exec with
+ // its dump on the way: it is there again soon.
+ if (std.mem.eql(u8, std.mem.sliceTo(why, 0), upgrading) or (have == null and cutListed(why, session))) redial(gpa, path, session, why, have, true, null) else null) orelse return null, why)) orelse return null;
defer {
if (have) |h| h.store(gpa, j) else gpa.free(j.dump);
j.dump = &.{};
@@ -3280,6 +3298,9 @@ fn redial(gpa: Allocator, path: []const u8, session: []const u8, why: *[600]u8,
_ = std.fmt.bufPrint(why, "{s}\x00", .{upgrade_words}) catch {};
return null;
}
+ // Its daemon lists no such session: it is gone, not away a moment
+ // (an Upgrade keeps it listed throughout).
+ if (std.mem.startsWith(u8, words, "no session called ")) return null;
if (!patient or tries > 200) return null;
const ts: libc.timespec = .{ .sec = 0, .nsec = 100 * std.time.ns_per_ms };
_ = libc.nanosleep(&ts, null);