Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Fix PeerManager signalAvailabiity() race #417

Merged
merged 1 commit into from
Jun 10, 2020
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
3 changes: 3 additions & 0 deletions internal/peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func (pm *PeerManager) UnregisterSession(ses uint64) {
// signalAvailability is called when a peer's connectivity changes.
// It informs interested sessions.
func (pm *PeerManager) signalAvailability(p peer.ID, isConnected bool) {
pm.psLk.Lock()
defer pm.psLk.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we call this when holding the pqLk, is that fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I believe it is ok - we call signalAvailability() from Connect() / Disconnect() which are called from the networking layer.

signalAvailability() calls sessionWantSender.SignalAvailability() which just adds something to a channel in an explicitly non-blocking fashion, so I don't believe it can cause a deadlock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I think we can tighten these locks a bit. We may even be able to split the peerWantManager lock and the peerQueue lock into two.


sesIds, ok := pm.peerSessions[p]
if !ok {
return
Expand Down