diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/replica.zig | 25 |
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); |
