peer: Protect handlePongMsg with p.statsMtx

This commit is contained in:
Josh Rickmar 2018-09-06 13:00:31 -04:00
parent 999ee7d863
commit 00a3f0eb60

View File

@ -947,11 +947,13 @@ func (p *Peer) handlePongMsg(msg *wire.MsgPong) {
// and overlapping pings will be ignored. It is unlikely to occur
// without large usage of the ping rpc call since we ping infrequently
// enough that if they overlap we would have timed out the peer.
p.statsMtx.Lock()
if p.lastPingNonce != 0 && msg.Nonce == p.lastPingNonce {
p.lastPingMicros = time.Since(p.lastPingTime).Nanoseconds()
p.lastPingMicros /= 1000 // convert to usec.
p.lastPingNonce = 0
}
p.statsMtx.Unlock()
}
// readMessage reads the next wire message from the peer with logging.