summaryrefslogtreecommitdiff
path: root/core/replica.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/replica.zig')
-rw-r--r--core/replica.zig28
1 files changed, 26 insertions, 2 deletions
diff --git a/core/replica.zig b/core/replica.zig
index 56fc4a59..97da9c74 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -3112,6 +3112,26 @@ 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 link cut with no last word (`why` its hang-up) whose session its
+/// daemon lists still: an Upgrade's exec cut it, a dump on the way past the
+/// clients' flush (`Peers.refuseAll`), whichever build the session is, 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. Near, this machine's daemon is asked; far, the dial again is
+/// the asking (the far daemon's "no session called" ends it: `redial`).
+pub fn cutListed(why: []const u8, session: []const u8, far: bool) bool {
+ if (!std.mem.startsWith(u8, std.mem.sliceTo(why, 0), "the session hung up")) return false;
+ if (far) return true;
+ 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 +3171,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 cutListed(why, session, have != null)) 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 +3301,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);