Skip to content
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.
Comment thread
qdm12 marked this conversation as resolved.
return nil, fmt.Errorf("%w: peer id %s", errPeerDisconnected, peer)
}

peerMutex.Lock()
defer peerMutex.Unlock()

Expand Down