summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/replica.zig25
-rw-r--r--runtime/client.zig4
-rw-r--r--test/daemon.py38
3 files changed, 62 insertions, 5 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);
diff --git a/runtime/client.zig b/runtime/client.zig
index d4b76a1b..789cac27 100644
--- a/runtime/client.zig
+++ b/runtime/client.zig
@@ -218,6 +218,10 @@ pub fn Loop(comptime Frontend: type) type {
reader.join();
_ = libc.close(s.joined.fd);
s.joined.rest.deinit(s.gpa);
+ // Its link cut with no word by a session that is there still
+ // (an Upgrade's exec): joined again, as when told so.
+ if (link.gone and link.refused == null and link.ended == null and !link.left and s.have == null and replica.cutListed("the session hung up", s.dial.session))
+ link.refused = std.heap.c_allocator.dupe(u8, replica.upgrading) catch null;
// Why it joins again is in its notice until a key.
if (!link.rejoins()) {
// What it made since it joined, kept for its next start.
diff --git a/test/daemon.py b/test/daemon.py
index 2c86c04f..83c024c4 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -871,7 +871,7 @@ def pair_rows(binary):
shutil.rmtree(root, ignore_errors=True)
-def attach_upgrading(binary, rounds=6):
+def attach_upgrading(binary, rounds=6, dump=True):
"""`pardes attach` as its session upgrades: started at once after the
Upgrade's word, it is handed to the session before the exec; told the
session is upgrading (never cut by the exec unanswered: "hung up before
@@ -915,8 +915,40 @@ def attach_upgrading(binary, rounds=6):
nine.socket.close()
assert subprocess.run([binary, 'kill', name], env=e, capture_output=True, timeout=30).returncode == 0
wait_for('the session ended', lambda: not alive(session), timeout=30)
+ # A join whose dump is still on its way when the Upgrade comes (a
+ # 100 MB file: the flush before the exec lets it go cut): it joins
+ # again, as one told so does; never "let this client go".
+ # Once a run (plain mode, --attach-upgrading): a slow round.
+ if dump:
+ big = root / 'big.txt'
+ with open(big, 'w') as f:
+ f.write('a line of a big file, long enough to be a fair line of text in a log: 0123456789\n' * 1_250_000)
+ out = subprocess.run([binary, 'new', '--detach=big', str(big)], env=env, cwd=root, capture_output=True,
+ timeout=60, stdin=subprocess.DEVNULL)
+ assert out.returncode == 0, out
+ sock = root / 'pardes-9p-big.sock'
+ nine = Client(sock)
+ session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid'])
+ for k in range(2):
+ t = Term(30, 100)
+ terms.append(t)
+ a = t.spawn([binary, 'attach', 'big'], env)
+ listed = lambda: subprocess.run([binary, 'ps'], env=env, capture_output=True).stdout.decode() # noqa: E731
+ wait_for('the attach joined', lambda: f'client {a.pid} ' in listed() or a.poll() is not None, timeout=60)
+ before = sock.stat().st_ino
+ nine.write('/ctl', b'Upgrade\n')
+ wait_for('joined again, or gone', lambda: b'joined again' in t.text() or a.poll() is not None, timeout=180)
+ assert a.poll() is None, ('a join cut mid-dump', k, a.returncode, t.text()[-120:])
+ a.terminate()
+ a.wait(timeout=20)
+ wait_for('the session exec\'d', lambda: sock.stat().st_ino != before, timeout=60)
+ nine.socket.close()
+ nine = reconnect(sock)
+ nine.socket.close()
+ assert subprocess.run([binary, 'kill', 'big'], env=env, capture_output=True, timeout=30).returncode == 0
+ wait_for('the big session ended', lambda: not alive(session), timeout=30)
print(f'attach upgrading: an attach started as its session upgrades joins the new process ({rounds} of {rounds}, '
- 'without the variable and with it)')
+ 'without the variable and with it)' + ('; a join whose 100 MB dump the exec cut joined again, 2 of 2' if dump else ''))
finally:
for p in processes(root):
try:
@@ -3486,7 +3518,7 @@ if __name__ == '__main__':
elif sys.argv[1:2] == ['--pair']:
pair(sys.argv[2])
pair_rows(sys.argv[2])
- attach_upgrading(sys.argv[2])
+ attach_upgrading(sys.argv[2], dump=False)
pair_upgrade_views(sys.argv[2])
elif sys.argv[1:2] == ['--attach-upgrading']:
attach_upgrading(sys.argv[2])