Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(share/discovery): deadlock in limitedSet #2190

Merged
merged 1 commit into from
May 13, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 2 additions & 5 deletions share/availability/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,8 @@ func (d *Discovery) disconnectsLoop(ctx context.Context, sub event.Subscription)
return
}

if evnt := e.(event.EvtPeerConnectednessChanged); evnt.Connectedness == network.NotConnected {
if !d.set.Contains(evnt.Peer) {
continue
}

evnt := e.(event.EvtPeerConnectednessChanged)
if evnt.Connectedness == network.NotConnected && d.set.Contains(evnt.Peer) {
d.host.ConnManager().Unprotect(evnt.Peer, rendezvousPoint)
d.connector.Backoff(evnt.Peer)
d.set.Remove(evnt.Peer)
Expand Down
7 changes: 3 additions & 4 deletions share/availability/discovery/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (ps *limitedSet) Size() uint {
func (ps *limitedSet) Add(p peer.ID) (added bool) {
ps.lk.Lock()
if _, ok := ps.ps[p]; ok {
ps.lk.Unlock()
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
return false
}
ps.ps[p] = struct{}{}
Expand All @@ -65,10 +66,8 @@ func (ps *limitedSet) Add(p peer.ID) (added bool) {

func (ps *limitedSet) Remove(id peer.ID) {
ps.lk.Lock()
defer ps.lk.Unlock()
if ps.limit > 0 {
delete(ps.ps, id)
}
delete(ps.ps, id)
ps.lk.Unlock()
}

// Peers returns all discovered peers from the set.
Expand Down