The panic happens when calling both RandomPeers and DeletePeer in parallel. The RandomPeers function didn't hold the mutex throughout the function and would encounter an index-out-of-range if the address had been deleted. A test has been added to reproduce the panic.
The fix changes the RandomPeers function to hold the mutex until returning. The performance still looks acceptable in my opinion (90 microseconds with 50-100 peers in the dht)
The panic happens when calling both
RandomPeers
andDeletePeer
in parallel. TheRandomPeers
function didn't hold the mutex throughout the function and would encounter anindex-out-of-range
if the address had been deleted. A test has been added to reproduce the panic.The fix changes the
RandomPeers
function to hold the mutex until returning. The performance still looks acceptable in my opinion (90 microseconds with 50-100 peers in the dht)