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

fix(dot/network): re-add nil mutex check for disconnected peer #2408

Merged
merged 2 commits into from
Mar 21, 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
8 changes: 8 additions & 0 deletions dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtoc
}, peer)
}

var errPeerDisconnected = errors.New("peer disconnected")

func (s *Service) sendHandshake(peer peer.ID, hs Handshake, info *notificationsProtocol) (libp2pnetwork.Stream, error) {
// multiple processes could each call this upcoming section, opening multiple streams and
// sending multiple handshakes. thus, we need to have a per-peer and per-protocol lock
Expand All @@ -293,6 +295,12 @@ func (s *Service) sendHandshake(peer peer.ID, hs Handshake, info *notificationsP
// so we cannot have a method on peersData to lock and unlock the mutex
// from the map
peerMutex := info.peersData.getMutex(peer)
if peerMutex == nil {
// Note: the only place the mutex is deleted is when the peer disconnects.
// If it doesn't exist, the peer never connected either.
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("%w: peer id %s", errPeerDisconnected, peer)
}

peerMutex.Lock()
defer peerMutex.Unlock()

Expand Down