holepunch: replace timing-based test wait with identify-driven synchronization#3506
Open
Deln0r wants to merge 1 commit into
Open
holepunch: replace timing-based test wait with identify-driven synchronization#3506Deln0r wants to merge 1 commit into
Deln0r wants to merge 1 commit into
Conversation
…onization The TestFailuresOnResponder subtests block on a 100 ms sleep followed by an EventuallyWithT poll of h1.Mux().Protocols(); libp2p#3440 records that the order of those two steps was found to matter empirically without a clear root cause. The actual sequencing requirement is: 1. Before h1.Connect, h1 must have installed its holepunch stream handler. (*Service).waitForPublicAddr in p2p/protocol/holepunch/svc.go gates SetStreamHandler on observing a public address, so this step is genuinely async from libp2p.New returning. 2. Between h1.Connect and h2.NewStream, h2 must have learned about h1's protocol set via the identify exchange. NewStream dispatches on h2's peerstore view, which the identify subscription populates asynchronously after Connect. Replace the magic sleep with an explicit poll of h1.Mux().Protocols() on a 10 ms cadence, then add a second poll on h2.Peerstore().GetProtocols(h1.ID()) after Connect. Both poll intervals are tight (10 ms) so a stable steady state is observed quickly without adding fixed latency to the happy path. Updates libp2p#3440.
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.
Updates #3440. Not closing because I couldn't reliably reproduce the original flake to confirm the fix in CI (see the "Test plan" caveat at the bottom).
Why the test is flaky
TestFailuresOnRespondercurrently relies on a 100 mstime.Sleepplus anEventuallyWithTpoll ofh1.Mux().Protocols(). The issue notes that the order of those two steps was found to matter empirically without a clear root cause. Reading(*Service).waitForPublicAddrinp2p/protocol/holepunch/svc.go, the actual asynchronous events the test depends on are:h1.Connect:holepunch.Servicemust have installed its stream handler. That call is gated on the local node observing at least one public address, so it is genuinely asynchronous fromlibp2p.Newreturning.h1.Connectandh2.NewStream(... holepunch.Protocol):h2must have learned abouth1's protocol set via the identify exchange.NewStreamdispatches onh2's peerstore view, which the identify subscription populates asynchronously afterConnect.The current code only covers (1). (2) is implicit, which is why the test still races when identify lags
Connect.Change
EventuallyWithTwith a tighterEventually(10 ms poll, 5 s budget) and useslices.Containsfor the protocol check.h1.Connect, add a secondEventuallythat pollsh2.Peerstore().GetProtocols(h1.ID())until it containsholepunch.Protocol. This is the deterministic version of "wait for identify to land".Net effect: both async dependencies are explicitly waited on, the happy path takes ~tens of milliseconds instead of a fixed 100 ms sleep, and the comment about the order being load-bearing goes away.
Test plan — caveat
I couldn't reproduce the original flake on my workstation in either branch: stock
masterpanics insimnet.SimConn.WriteTo("upPacketReceiver is nil. Did you forget to call simconn.SetUpPacketReceiver?") on macOS / Go 1.25, before the test body even runs. The panic reproduces on stockupstream/masterwith no changes, so it's not caused by this PR. If CI has a working repro path for the flake, the right validation is to runTestFailuresOnResponderwith-count=100on this branch and confirm zero failures.I'm happy to follow up with a focused environment fix for the simconn panic if that's of independent interest — let me know.
Notes