Skip to content

fix(backend-p2p): wait for both session ends in sync integration tests - #108

Merged
Mearman merged 2 commits into
mainfrom
fix/wan-gossip-introduction-race
Dec 1, 2026
Merged

Mearman merged 2 commits into
mainfrom
fix/wan-gossip-introduction-race

Conversation

@Mearman

@Mearman Mearman commented Dec 1, 2026

Copy link
Copy Markdown
Member

Fixes #104

The failure is in the test's wait, not in peer introduction. connect_to returns once the dialler's side of the TLS handshake is done; with TLS 1.3 that is as soon as the dialler has written its final flight. The listener reads that flight, records the peer (record_peer in handle_inbound) and registers the session in a task of its own. wan_gossip_introduces_peers_transitively slept 300 ms and assumed B had done all of that for both A and C, which a loaded Windows runner does not always manage. In the daemon nothing depends on that timing: the gossip loop broadcasts every 60 s from whatever the peer book holds then, so a peer recorded a moment later goes out in the next round.

Reproduction: the pre-fix test body, unchanged except that C dials B through a proxy that forwards C's ClientHello and then holds C's bytes for 1.5 s, fails every run with B should know C before gossip. The updated test, with that proxy kept permanently on C's dial (1 s hold), passes.

Changes:

  • sync_integration.rs: every fixed settle sleep and every ad hoc short polling loop is replaced by a poll on the state it needs through the shared harness assert_eventually and its deadline. connect_via_listener now waits for has_peer on both ends, which also implies both peer-book entries, and the gossip test waits for both of B's sessions before broadcasting, because the single gossip frame reaches only sessions B has registered. version_vectors_resolve_concurrent_upload used to assert after a sleep with checks that held even when no frame was exchanged; it now waits for both sides to agree on the merged row. The 1100 ms sleeps remain because modification times are stored in whole seconds, so they order two writes rather than wait for a peer, and the 5 s timeout in concurrent_downloads_do_not_serialise bounds the property under test.
  • run_session_loop: the opening Handshake is now queued before the session handle is inserted into the peer map. Before this change, on a multi-threaded runtime, another task (a gossip broadcast or an index update) could queue a frame on the new handle before the Handshake. The peer would then read a non-Handshake first frame and downgrade the session to the pre-version domains. I found this while tracing the gossip path. The #[tokio::test] single-threaded runtime cannot hit it, so it is not what failed here, and I have no deterministic test for it.

Runs on Linux in the pinned 1.96.0 toolchain: sync_integration 30 times in a row, plus 100 times with the container limited to one CPU, all passing; cargo fmt --check, cargo clippy --workspace and cargo test --workspace pass.

run_session_loop inserted the session's handle into the peer map and
only then queued the opening Handshake frame. On a multi-threaded
runtime another task (a gossip broadcast, an index update) can take
the handle in that gap and queue a frame first; the peer then reads a
non-Handshake first frame and downgrades the session to the
pre-version Content and Management domains.

Queue the Handshake before the handle is visible, so it is always the
first frame the writer sends.
connect_to returns once the dialler's side of the TLS handshake is
done. The listener reads the dialler's final flight, records the peer
and registers the session in a task of its own, so the fixed settle
sleeps in sync_integration were guesses at how long that takes. On a
loaded Windows runner the guess ran out before B had accepted C, and
wan_gossip_introduces_peers_transitively failed with "B should know C
before gossip".

Every wait in the file now polls for the state it needs with the
shared harness assert_eventually and its deadline: both ends of each
link via has_peer, index entries, last-write-wins convergence,
tombstones, conflict copies, and the gossip result. The gossip test
also needs B to hold A's session before it broadcasts, since the one
frame reaches only registered sessions.

C now dials B through a proxy that holds C's bytes after the
ClientHello, so every run of the gossip test has connect_to return
before B has accepted C: the old wait fails under it, the new one
passes.

version_vectors_resolve_concurrent_upload previously asserted after a
fixed sleep with checks that held even if no frame was exchanged; it
now waits for both sides to agree on the merged row first.

The 1100 ms sleeps stay: modification times are stored in whole
seconds, so they order two writes rather than wait for a peer.
Copilot AI balanced review requested due to automatic review settings December 1, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Mearman
Mearman marked this pull request as ready for review December 1, 2026 17:18
@Mearman
Mearman merged commit 699cb5e into main Dec 1, 2026
215 of 220 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wan_gossip_introduces_peers_transitively failed on Windows

2 participants