holepunch: initialize timeout before registering notifiee - #3529
Merged
Conversation
sukunrt
reviewed
Jul 29, 2026
sukunrt
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix. The fix is fine, but the test seems too tailored to the internals. Can you see if there's a less intrusive way to test this? Maybe we can run lots of hosts in parallel and try to trigger the race?
Otherwise It's fine to fix this without a test.
Contributor
Author
Thanks for the feedback, I'm traveling and should be able to get to it the week after next. |
The hole-punch network notifiee was registered before the service copied directDialTimeout onto it. An inbound relayed connection could therefore read the field concurrently and observe the zero value. Pass the configured timeout into the constructor so every field is initialized before Network.Notify publishes the object. Add a deterministic regression test that inspects the timeout at registration. Signed-off-by: Tristan Wilson <commits@tristanwilson.earth>
The test depends too much on the package internals. The race window it checks is closed by the previous commit, and is infeasible to trigger with real hosts. Assisted-By: Claude Fable 5
sukunrt
force-pushed
the
fix/holepunch-init-race
branch
from
August 3, 2026 12:28
ab0548f to
894fa09
Compare
Member
|
That's fine, I can do that. |
sukunrt
approved these changes
Aug 3, 2026
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.
Description
waitForPublicAddrconstructed aholePuncher, whose constructor registered the network notifiee, and only then assigneddirectDialTimeoutto the returned object.An inbound relayed connection could therefore enter
DirectConnectand read the timeout concurrently with that assignment. Besides being a data race, a callback in this startup window could observe the zero value and create an immediately expired dial context.This change passes the configured timeout into the constructor and initializes it before
Network.Notifypublishes the hole puncher. It also adds a deterministic regression test that inspects the configured value at the registration boundary.No exported API or lifecycle behavior changes.
Reproduction
This was found while running a private downstream project's end-to-end DCUtR test under the race detector. It was initially observed with go-libp2p v0.48.0 and reproduced on current
masterbefore this change:The new unit test provides a deterministic form of the same ordering check. Without the fix it observes:
Testing
The private downstream DCUtR reproduction also passed 20 consecutive race-detector runs after the fix, followed by its package-level and full repository race suites.
AI assistance disclosure
This PR was developed with substantial OpenAI Codex assistance. Codex analyzed the race, authored the minimal code change and regression test, ran the validation described above, and drafted this description. I reviewed the result and am submitting it.