fix(kademlia): neighborhood rebroadcast sends wrong peer lists - #5595
Open
gacevicljubisa wants to merge 2 commits into
Open
fix(kademlia): neighborhood rebroadcast sends wrong peer lists#5595gacevicljubisa wants to merge 2 commits into
gacevicljubisa wants to merge 2 commits into
Conversation
gacevicljubisa
requested review from
acud,
akrem-chabchoub,
aloknerurkar,
janos,
martinconic and
sbackend123
September 3, 2026 09:54
acud
requested changes
Sep 3, 2026
| for j := 1; j < n; j++ { | ||
| wantAnnounces += j + 1 | ||
| } | ||
| if err := spinlock.Wait(spinLockWaitTime, func() bool { |
Contributor
There was a problem hiding this comment.
this package again... why not synctest and some other channel driven mocks or something? would really like to see this package go away from the codebase
|
|
||
| // RebroadcastNeighborhood runs the neighborhood gossip the manage loop | ||
| // performs every fifteen minutes. | ||
| func (k *Kad) RebroadcastNeighborhood(ctx context.Context) { |
Contributor
There was a problem hiding this comment.
i would test here the method that creates the set of peers to be sent to every peer separately. just unit test that the sets are correct. then calling discovery is either trivial (and can go without a test at all) or very simple to test.
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.
Checklist
Description
The 15-minute neighborhood rebroadcast in the kademlia manage loop builds each
neighbor's list with
append(neighbors[:i], neighbors[i+1:]...). That appendsinto the backing array of the slice the loop is still ranging over, so from the
second iteration on the loop reads already-overwritten entries. With four
neighbors
[a b c d]the loop actually sends:i=0 -> a: [b c d] (neighbors is now [b c d d])
i=1 -> c: [b d d]
i=2 -> d: [b d d]
i=3 -> d: [b d d]
Only the first neighbor gets a correct list,
bis never told anything,distold twice and told about itself, and the lists carry duplicates. Present since
#4412.
Changes:
slices.Concat, which allocates a fresh slice.rebroadcastNeighborhoodand expose it fromexport_test.go, so it can be driven without waiting fifteen minutes.TestRebroadcastNeighborhood: connects four peers with storage radius 0,waits for the connect-time announces to settle, runs one rebroadcast, and
asserts each neighbor receives exactly one message listing the other three
and never itself. The test fails on master with "received 6 peers, want 3".
Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
Related Issue (Optional)
Screenshots (if appropriate):
AI Disclosure