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

Conversation

dirkmc
Copy link
Contributor

@dirkmc dirkmc commented Jun 10, 2020

Fixes #415

@dirkmc dirkmc requested a review from Stebalien June 10, 2020 20:19
@@ -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.

@Stebalien Stebalien merged commit 06129d6 into master Jun 10, 2020
Jorropo pushed a commit to Jorropo/go-libipfs that referenced this pull request Jan 26, 2023
Fix PeerManager signalAvailabiity() race

This commit was moved from ipfs/go-bitswap@06129d6
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Races in peermanager
2 participants