diff options
| -rw-r--r-- | core/replica.zig | 16 | ||||
| -rw-r--r-- | runtime/client.zig | 2 | ||||
| -rw-r--r-- | test/daemon.py | 8 |
3 files changed, 22 insertions, 4 deletions
diff --git a/core/replica.zig b/core/replica.zig index 448c428f..79abd977 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -3292,6 +3292,9 @@ pub const Link = struct { fresh: bool = true, /// How far behind it was as it let its link go (`rejoins` says so). lagged: u64 = 0, + /// Its link crosses machines (a `Have`: ssh's forward, a relay): fallen + /// behind, it dials again (`backHere`). + far: bool = false, /// A pair's first join, its own boot not confirmed yet: its inputs /// kept here, not sent (`release`; client.zig `confirm`). held: ?std.ArrayListUnmanaged(u8) = null, @@ -3526,7 +3529,15 @@ pub const Link = struct { /// a cut's keep the link, an Upgrade's and a Restore's end it, which the /// join there finds): its goodbye and hello are said on it (`comeBack`). /// One that is gone, or a last word, is not. + /// THE SECOND ROAD: a far client that fell behind dials again (a new + /// connection; the one it leaves is shut): over its own link it would + /// first read through all that link holds for it, which a relay or a + /// forward buffers without bound (test/daemon.py `far_flood`: 49-68 s + /// to agree after the flood against 22.7 s by a dial). Bounded flight + /// (the session never more than a window past what its client has + /// taken) replaces it, and this line goes. pub fn backHere(c: *const Link) bool { + if (c.far and c.lagged != 0) return false; return !c.gone and c.ended == null and !c.left and (c.r.diverged != null or c.lagged != 0 or c.refused != null); } @@ -6053,6 +6064,11 @@ test "a client whose session's units come more than two seconds later than its q // core is behind on purpose, no divergence. link.take(.{ .checked = digestOf(a) +% 1 }); try std.testing.expect(r.diverged == null); + // It comes back over its link; far, it dials again (`backHere`). + try std.testing.expect(link.backHere()); + link.far = true; + try std.testing.expect(!link.backHere()); + link.far = false; try std.testing.expect(link.rejoins()); try std.testing.expectEqualStrings("joined again: 2.1 s behind", link.notice()); try std.testing.expect(!link.rejoins()); diff --git a/runtime/client.zig b/runtime/client.zig index 2fbc75c8..1d348aea 100644 --- a/runtime/client.zig +++ b/runtime/client.zig @@ -175,7 +175,7 @@ pub fn Loop(comptime Frontend: type) type { frames: *pardes.FrameStats, pub fn init(fe: *Frontend, s: *Start) !L { - var l: L = .{ .link = .{ .r = s.r, .fd = s.joined.fd }, .fe = fe, .frames = &s.frames }; + var l: L = .{ .link = .{ .r = s.r, .fd = s.joined.fd, .far = s.have != null }, .fe = fe, .frames = &s.frames }; try l.link.fromEnv(s.gpa, s.env); return l; } diff --git a/test/daemon.py b/test/daemon.py index c22d95d4..caa1272b 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -2382,13 +2382,15 @@ def far_flood(binary): # Queued behind the flood, let go for its lag, joined again from a # dump: a link of its ended (its stats line), and its notice says why. assert joins(stats), ('no link of the far client ended under the flood', checks(stats)) - # Over its own link (the relay's one connection for it), each join's - # time and the KB it was sent; the flood's end to its agreement. + # Fallen behind, a far client dials again (core/replica.zig + # `Link.backHere`: the second road until bounded flight): a new + # connection, not what the old one holds for it read through; each + # join's time and the KB it was sent; the flood's end to its agreement. same = sockets(c.pid) == links print(f'far flood: the far client\'s link {"the same" if same else "another"} after {len(joins(stats))} joins again ' f'(join ms {[j.get("join_ms") for j in joins(stats)]}, sent KB {[j.get("sent_kb") for j in joins(stats)]}); ' f'agreed {time.monotonic() - ended_at:.1f} s after yes ended') - assert same, ('the far client joined again over its own link', links, sockets(c.pid)) + assert not same, ('the far client behind dialled again: another connection', links, sockets(c.pid)) wait_for('the far client\'s notice of its join again', lambda: b'joined again: ' in t.text() and b' s behind' in t.text(), timeout=30) os.write(t.master, b'echo from-far\r') wait_for('the far client\'s keys in the shell', lambda: b'from-far' in nine.read(f'/pane/{shell}/body'), timeout=30) |
