Skip to content

Commit 6dee1e5

Browse files
authored
Merge pull request #622 from libp2p/fix/evt-channel-closed
fix: don't spin when the event channel is closed
2 parents 7224e2a + fafd870 commit 6dee1e5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dual/dual.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error {
9797
func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo {
9898
reqCtx, cancel := context.WithCancel(ctx)
9999
outCh := make(chan peer.AddrInfo)
100-
subCtx, errCh := routing.RegisterForQueryEvents(reqCtx)
100+
subCtx, evtCh := routing.RegisterForQueryEvents(reqCtx)
101101
wanCh := dht.WAN.FindProvidersAsync(subCtx, key, count)
102102
lanCh := dht.LAN.FindProvidersAsync(subCtx, key, count)
103103
zeroCount := (count == 0)
@@ -111,8 +111,10 @@ func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int)
111111
for (zeroCount || count > 0) && (wanCh != nil || lanCh != nil) {
112112
var ok bool
113113
select {
114-
case qEv, ok = <-errCh:
115-
if ok && qEv != nil && qEv.Type != routing.QueryError {
114+
case qEv, ok = <-evtCh:
115+
if !ok {
116+
evtCh = nil
117+
} else if qEv != nil && qEv.Type != routing.QueryError {
116118
routing.PublishQueryEvent(reqCtx, qEv)
117119
}
118120
continue

0 commit comments

Comments
 (0)