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

Commit

Permalink
Merge pull request #412 from ipfs/fix/race
Browse files Browse the repository at this point in the history
fix: avoid taking accessing the peerQueues without taking the lock
  • Loading branch information
Stebalien authored Jun 10, 2020
2 parents 3ab1ede + 69e72e4 commit 25318da
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workflows:
- ci-go/test:
race: true
name: "ci-go/test/race"
- ci-go/benchmark:
tolerance: 50
requires:
- ci-go/test
#- ci-go/benchmark:
# tolerance: 50
# requires:
# - ci-go/test
5 changes: 1 addition & 4 deletions internal/peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (pm *PeerManager) getOrCreate(p peer.ID) PeerQueue {

// RegisterSession tells the PeerManager that the given session is interested
// in events about the given peer.
func (pm *PeerManager) RegisterSession(p peer.ID, s Session) bool {
func (pm *PeerManager) RegisterSession(p peer.ID, s Session) {
pm.psLk.Lock()
defer pm.psLk.Unlock()

Expand All @@ -210,9 +210,6 @@ func (pm *PeerManager) RegisterSession(p peer.ID, s Session) bool {
pm.peerSessions[p] = make(map[uint64]struct{})
}
pm.peerSessions[p][s.ID()] = struct{}{}

_, ok := pm.peerQueues[p]
return ok
}

// UnregisterSession tells the PeerManager that the given session is no longer
Expand Down
2 changes: 1 addition & 1 deletion internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
type PeerManager interface {
// RegisterSession tells the PeerManager that the session is interested
// in a peer's connection state
RegisterSession(peer.ID, bspm.Session) bool
RegisterSession(peer.ID, bspm.Session)
// UnregisterSession tells the PeerManager that the session is no longer
// interested in a peer's connection state
UnregisterSession(uint64)
Expand Down
4 changes: 1 addition & 3 deletions internal/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ func newFakePeerManager() *fakePeerManager {
}
}

func (pm *fakePeerManager) RegisterSession(peer.ID, bspm.Session) bool {
return true
}
func (pm *fakePeerManager) RegisterSession(peer.ID, bspm.Session) {}
func (pm *fakePeerManager) UnregisterSession(uint64) {}
func (pm *fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {}
func (pm *fakePeerManager) BroadcastWantHaves(ctx context.Context, cids []cid.Cid) {
Expand Down
3 changes: 1 addition & 2 deletions internal/session/sessionwantsender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ func newMockPeerManager() *mockPeerManager {
}
}

func (pm *mockPeerManager) RegisterSession(p peer.ID, sess bspm.Session) bool {
func (pm *mockPeerManager) RegisterSession(p peer.ID, sess bspm.Session) {
pm.lk.Lock()
defer pm.lk.Unlock()

pm.peerSessions[p] = sess
return true
}

func (pm *mockPeerManager) has(p peer.ID, sid uint64) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/sessionmanager/sessionmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type fakePeerManager struct {
cancels []cid.Cid
}

func (*fakePeerManager) RegisterSession(peer.ID, bspm.Session) bool { return true }
func (*fakePeerManager) RegisterSession(peer.ID, bspm.Session) {}
func (*fakePeerManager) UnregisterSession(uint64) {}
func (*fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {}
func (*fakePeerManager) BroadcastWantHaves(context.Context, []cid.Cid) {}
Expand Down

0 comments on commit 25318da

Please sign in to comment.