Skip to content

Commit

Permalink
Merge pull request #622 from libp2p/fix/evt-channel-closed
Browse files Browse the repository at this point in the history
fix: don't spin when the event channel is closed
  • Loading branch information
Stebalien authored Apr 29, 2020
2 parents 7224e2a + fafd870 commit 6dee1e5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dual/dual.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo {
reqCtx, cancel := context.WithCancel(ctx)
outCh := make(chan peer.AddrInfo)
subCtx, errCh := routing.RegisterForQueryEvents(reqCtx)
subCtx, evtCh := routing.RegisterForQueryEvents(reqCtx)
wanCh := dht.WAN.FindProvidersAsync(subCtx, key, count)
lanCh := dht.LAN.FindProvidersAsync(subCtx, key, count)
zeroCount := (count == 0)
Expand All @@ -111,8 +111,10 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
for (zeroCount || count > 0) && (wanCh != nil || lanCh != nil) {
var ok bool
select {
case qEv, ok = <-errCh:
if ok && qEv != nil && qEv.Type != routing.QueryError {
case qEv, ok = <-evtCh:
if !ok {
evtCh = nil
} else if qEv != nil && qEv.Type != routing.QueryError {
routing.PublishQueryEvent(reqCtx, qEv)
}
continue
Expand Down

0 comments on commit 6dee1e5

Please sign in to comment.