Repository navigation
fix(backend-p2p): wait for both session ends in sync integration tests - #108
Merged
Merged
Conversation
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.
Mearman
marked this pull request as ready for review
December 1, 2026 17:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #104
The failure is in the test's wait, not in peer introduction.
connect_toreturns 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_peerinhandle_inbound) and registers the session in a task of its own.wan_gossip_introduces_peers_transitivelyslept 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 harnessassert_eventuallyand its deadline.connect_via_listenernow waits forhas_peeron 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_uploadused 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 inconcurrent_downloads_do_not_serialisebounds 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_integration30 times in a row, plus 100 times with the container limited to one CPU, all passing;cargo fmt --check,cargo clippy --workspaceandcargo test --workspacepass.