This code was attempting to use the "compare racily, then lock
and compare again" idiom to try and reduce lock contention.
However, that idiom is not safe to use unless the comparison
uses atomic operations, which this does not.
This change simply deletes the racy read. This makes the code
correct, but potentially increases lock contention.
Signed-off-by: David Anderson <danderson@tailscale.com>
func (peer *Peer) ReceivedWithKeypair(receivedKeypair *Keypair) bool {
keypairs := &peer.keypairs
- if keypairs.next != receivedKeypair {
- return false
- }
keypairs.Lock()
defer keypairs.Unlock()
if keypairs.next != receivedKeypair {