Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v1.7] server: Fix syncNotified race. #2931

Merged
merged 1 commit into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,10 @@ type serverPeer struct {

// The following fields are used to synchronize the net sync manager and
// server.
syncNotified bool
txProcessed chan struct{}
blockProcessed chan struct{}
syncNotifiedMtx sync.Mutex
davecgh marked this conversation as resolved.
Show resolved Hide resolved
syncNotified bool
txProcessed chan struct{}
blockProcessed chan struct{}

// peerNa is network address of the peer connected to.
peerNa *wire.NetAddress
Expand Down Expand Up @@ -2250,7 +2251,10 @@ func (s *server) peerDoneHandler(sp *serverPeer) {

// Notify the net sync manager the peer is gone if it was ever notified that
// the peer existed.
if sp.syncNotified {
sp.syncNotifiedMtx.Lock()
syncNotified := sp.syncNotified
sp.syncNotifiedMtx.Unlock()
if syncNotified {
s.syncManager.DonePeer(sp.Peer)
}

Expand Down Expand Up @@ -2314,7 +2318,9 @@ out:
// unless it was disconnected above.
if p.Connected() {
s.syncManager.NewPeer(p.Peer)
p.syncNotifiedMtx.Lock()
p.syncNotified = true
p.syncNotifiedMtx.Unlock()
}

// Disconnected peers.
Expand Down