Unverified Commit 25318da3 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #412 from ipfs/fix/race

fix: avoid taking accessing the peerQueues without taking the lock
parents 3ab1ede0 69e72e4d
...@@ -12,7 +12,7 @@ workflows: ...@@ -12,7 +12,7 @@ workflows:
- ci-go/test: - ci-go/test:
race: true race: true
name: "ci-go/test/race" name: "ci-go/test/race"
- ci-go/benchmark: #- ci-go/benchmark:
tolerance: 50 # tolerance: 50
requires: # requires:
- ci-go/test # - ci-go/test
...@@ -198,7 +198,7 @@ func (pm *PeerManager) getOrCreate(p peer.ID) PeerQueue { ...@@ -198,7 +198,7 @@ func (pm *PeerManager) getOrCreate(p peer.ID) PeerQueue {
// RegisterSession tells the PeerManager that the given session is interested // RegisterSession tells the PeerManager that the given session is interested
// in events about the given peer. // 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() pm.psLk.Lock()
defer pm.psLk.Unlock() defer pm.psLk.Unlock()
...@@ -210,9 +210,6 @@ func (pm *PeerManager) RegisterSession(p peer.ID, s Session) bool { ...@@ -210,9 +210,6 @@ func (pm *PeerManager) RegisterSession(p peer.ID, s Session) bool {
pm.peerSessions[p] = make(map[uint64]struct{}) pm.peerSessions[p] = make(map[uint64]struct{})
} }
pm.peerSessions[p][s.ID()] = struct{}{} pm.peerSessions[p][s.ID()] = struct{}{}
_, ok := pm.peerQueues[p]
return ok
} }
// UnregisterSession tells the PeerManager that the given session is no longer // UnregisterSession tells the PeerManager that the given session is no longer
......
...@@ -30,7 +30,7 @@ const ( ...@@ -30,7 +30,7 @@ const (
type PeerManager interface { type PeerManager interface {
// RegisterSession tells the PeerManager that the session is interested // RegisterSession tells the PeerManager that the session is interested
// in a peer's connection state // 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 // UnregisterSession tells the PeerManager that the session is no longer
// interested in a peer's connection state // interested in a peer's connection state
UnregisterSession(uint64) UnregisterSession(uint64)
......
...@@ -136,9 +136,7 @@ func newFakePeerManager() *fakePeerManager { ...@@ -136,9 +136,7 @@ func newFakePeerManager() *fakePeerManager {
} }
} }
func (pm *fakePeerManager) RegisterSession(peer.ID, bspm.Session) bool { func (pm *fakePeerManager) RegisterSession(peer.ID, bspm.Session) {}
return true
}
func (pm *fakePeerManager) UnregisterSession(uint64) {} func (pm *fakePeerManager) UnregisterSession(uint64) {}
func (pm *fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {} func (pm *fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {}
func (pm *fakePeerManager) BroadcastWantHaves(ctx context.Context, cids []cid.Cid) { func (pm *fakePeerManager) BroadcastWantHaves(ctx context.Context, cids []cid.Cid) {
......
...@@ -59,12 +59,11 @@ func newMockPeerManager() *mockPeerManager { ...@@ -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() pm.lk.Lock()
defer pm.lk.Unlock() defer pm.lk.Unlock()
pm.peerSessions[p] = sess pm.peerSessions[p] = sess
return true
} }
func (pm *mockPeerManager) has(p peer.ID, sid uint64) bool { func (pm *mockPeerManager) has(p peer.ID, sid uint64) bool {
......
...@@ -64,7 +64,7 @@ type fakePeerManager struct { ...@@ -64,7 +64,7 @@ type fakePeerManager struct {
cancels []cid.Cid 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) UnregisterSession(uint64) {}
func (*fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {} func (*fakePeerManager) SendWants(context.Context, peer.ID, []cid.Cid, []cid.Cid) {}
func (*fakePeerManager) BroadcastWantHaves(context.Context, []cid.Cid) {} func (*fakePeerManager) BroadcastWantHaves(context.Context, []cid.Cid) {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment