nictuku/dht

Fix test data races

Closed this issue · 1 comments

I believe there are only two races: one in the call to ping(), another in the call to reachableNodes().

WARNING: DATA RACE
Read by goroutine 9:
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).hostPortToNode()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:52 +0x218
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).getOrCreateNode()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:121 +0x75
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).ping()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:404 +0x85
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).DoDHT()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:200 +0x1c6

Previous write by goroutine 5:
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).insert()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:108 +0x16c
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).getOrCreateNode()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:144 +0x40f
_/Users/yves/go/src/github.com/nictuku/dht.(*DHT).ping()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:404 +0x85
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:81 +0x1097
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Goroutine 9 (running) created at:
_/Users/yves/go/src/github.com/nictuku/dht.startDHTNode()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:64 +0x150
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:71 +0x43
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Goroutine 5 (running) created at:
testing.RunTests()
/Users/yves/go/src/pkg/testing/testing.go:377 +0xaec
testing.Main()
/Users/yves/go/src/pkg/testing/testing.go:313 +0xcd
main.main()
_/Users/yves/go/src/github.com/nictuku/dht/_test/_testmain.go:61 +0xda
runtime.main()
/Users/yves/go/src/pkg/runtime/proc.c:248 +0x91

WARNING: DATA RACE
Read by goroutine 5:
_/Users/yves/go/src/github.com/nictuku/dht.(*routingTable).reachableNodes()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:67 +0x21a
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:87 +0x2db
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Previous write by goroutine 9:
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).getOrCreateNode()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:142 +0x24c
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).ping()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:404 +0x85
_/Users/yves/go/src/github.com/nictuku/dht.(*DHT).DoDHT()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:200 +0x1c6

Goroutine 5 (running) created at:
testing.RunTests()
/Users/yves/go/src/pkg/testing/testing.go:377 +0xaec
testing.Main()
/Users/yves/go/src/pkg/testing/testing.go:313 +0xcd
main.main()
_/Users/yves/go/src/github.com/nictuku/dht/_test/_testmain.go:61 +0xda
runtime.main()
/Users/yves/go/src/pkg/runtime/proc.c:248 +0x91

Goroutine 9 (running) created at:
_/Users/yves/go/src/github.com/nictuku/dht.startDHTNode()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:64 +0x150
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:71 +0x43
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

WARNING: DATA RACE
Read by goroutine 5:
_/Users/yves/go/src/github.com/nictuku/dht.(*routingTable).reachableNodes()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:67 +0x21a
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:87 +0x2db
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Previous write by goroutine 9:

Goroutine 5 (running) created at:
testing.RunTests()
/Users/yves/go/src/pkg/testing/testing.go:377 +0xaec
testing.Main()
/Users/yves/go/src/pkg/testing/testing.go:313 +0xcd
main.main()
_/Users/yves/go/src/github.com/nictuku/dht/_test/_testmain.go:61 +0xda
runtime.main()
/Users/yves/go/src/pkg/runtime/proc.c:248 +0x91

Goroutine 9 (running) created at:
_/Users/yves/go/src/github.com/nictuku/dht.startDHTNode()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:64 +0x150
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:71 +0x43
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

WARNING: DATA RACE
Read by goroutine 5:
_/Users/yves/go/src/github.com/nictuku/dht.(*routingTable).reachableNodes()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:68 +0x244
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:87 +0x2db
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Previous write by goroutine 9:

Goroutine 5 (running) created at:
testing.RunTests()
/Users/yves/go/src/pkg/testing/testing.go:377 +0xaec
testing.Main()
/Users/yves/go/src/pkg/testing/testing.go:313 +0xcd
main.main()
_/Users/yves/go/src/github.com/nictuku/dht/_test/_testmain.go:61 +0xda
runtime.main()
/Users/yves/go/src/pkg/runtime/proc.c:248 +0x91

Goroutine 9 (running) created at:
_/Users/yves/go/src/github.com/nictuku/dht.startDHTNode()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:64 +0x150
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:71 +0x43
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

WARNING: DATA RACE
Read by goroutine 5:
_/Users/yves/go/src/github.com/nictuku/dht.(*routingTable).reachableNodes()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:67 +0x21a
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:87 +0x2db
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

Previous write by goroutine 9:
_/Users/yves/go/src/github.com/nictuku/dht.(_routingTable).getOrCreateNode()
/Users/yves/go/src/github.com/nictuku/dht/routing_table.go:142 +0x24c
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).processFindNodeResults()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:672 +0x54a
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).processPacket()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:363 +0xad1
_/Users/yves/go/src/github.com/nictuku/dht.(_DHT).DoDHT()
/Users/yves/go/src/github.com/nictuku/dht/dht.go:244 +0x84b

Goroutine 5 (running) created at:
testing.RunTests()
/Users/yves/go/src/pkg/testing/testing.go:377 +0xaec
testing.Main()
/Users/yves/go/src/pkg/testing/testing.go:313 +0xcd
main.main()
_/Users/yves/go/src/github.com/nictuku/dht/_test/_testmain.go:61 +0xda
runtime.main()
/Users/yves/go/src/pkg/runtime/proc.c:248 +0x91

Goroutine 9 (running) created at:
_/Users/yves/go/src/github.com/nictuku/dht.startDHTNode()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:64 +0x150
_/Users/yves/go/src/github.com/nictuku/dht.TestDHTLarge()
/Users/yves/go/src/github.com/nictuku/dht/dht_test.go:71 +0x43
testing.tRunner()
/Users/yves/go/src/pkg/testing/testing.go:301 +0xe8

For the record, the races are present in 3d78aad.