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: don't spin when the event channel is closed #622

Merged
merged 1 commit into from
Apr 29, 2020
Merged
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
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