Skip to content

Commit

Permalink
p2p/discover: use synchronous version of addSeenNode
Browse files Browse the repository at this point in the history
We get this data race when running TestTable_BucketIPLimit

Write at 0x00c00029c000 by goroutine 64:
  github.com/ethereum/go-ethereum/p2p/discover.(*Table).addSeenNodeSync()
      /home/runner/work/ronin/ronin/p2p/discover/table.go:570 +0x70a
  github.com/ethereum/go-ethereum/p2p/discover.(*Table).addSeenNode.func1()
      /home/runner/work/ronin/ronin/p2p/discover/table.go:527 +0x47
Previous read at 0x00c00029c000 by goroutine 57:
  github.com/ethereum/go-ethereum/p2p/discover.checkIPLimitInvariant()
      /home/runner/work/ronin/ronin/p2p/discover/table_test.go:187 +0x105
  github.com/ethereum/go-ethereum/p2p/discover.TestTable_BucketIPLimit()
      /home/runner/work/ronin/ronin/p2p/discover/table_test.go:177 +0x2e4
  testing.tRunner()
      /opt/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1576 +0x216
  testing.(*T).Run.func1()
      /opt/hostedtoolcache/go/1.20.10/x64/src/testing/testing.go:1629 +0x47

This commit changes TestTable_BucketIPLimit to use synchronous version of
addSeenNode to avoid the data race.
  • Loading branch information
minh-bq committed Oct 21, 2024
1 parent 58e9da0 commit 3166509
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion p2p/discover/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestTable_BucketIPLimit(t *testing.T) {
d := 3
for i := 0; i < bucketIPLimit+1; i++ {
n := nodeAtDistance(tab.self().ID(), d, net.IP{172, 0, 1, byte(i)})
tab.addSeenNode(n)
tab.addSeenNodeSync(n)
}
if tab.len() > bucketIPLimit {
t.Errorf("too many nodes in table")
Expand Down

0 comments on commit 3166509

Please sign in to comment.