Skip to content

Commit

Permalink
fix: bug from closing the iterator twice
Browse files Browse the repository at this point in the history
no need to close the channel. just the source iterator
  • Loading branch information
2color committed Dec 17, 2024
1 parent 49efe9b commit 8ca4d19
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions server_cached_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ func (r cachedRouter) FindProviders(ctx context.Context, key cid.Cid, limit int)
}

Check warning on line 64 in server_cached_router.go

View check run for this annotation

Codecov / codecov/patch

server_cached_router.go#L63-L64

Added lines #L63 - L64 were not covered by tests

iter := NewCacheFallbackIter(it, r, ctx)

go func() {
// make sure we close the iterator when the parent context is done
<-ctx.Done()
iter.Close()
}()

return iter, nil
}

Expand Down Expand Up @@ -199,6 +192,10 @@ func (it *cacheFallbackIter) Val() iter.Result[types.Record] {
return iter.Result[types.Record]{Err: errNoValueAvailable}

Check warning on line 192 in server_cached_router.go

View check run for this annotation

Codecov / codecov/patch

server_cached_router.go#L192

Added line #L192 was not covered by tests
}

func (it *cacheFallbackIter) Close() error {
return it.sourceIter.Close()
}

func (it *cacheFallbackIter) dispatchFindPeer(record types.PeerRecord) {
defer it.ongoingLookups.Add(-1)

Expand Down Expand Up @@ -231,12 +228,3 @@ func (it *cacheFallbackIter) dispatchFindPeer(record types.PeerRecord) {
it.findPeersResult <- record // pass back the record with no addrs
}

Check warning on line 229 in server_cached_router.go

View check run for this annotation

Codecov / codecov/patch

server_cached_router.go#L228-L229

Added lines #L228 - L229 were not covered by tests
}

func (it *cacheFallbackIter) Close() error {
for it.ongoingLookups.Load() > 0 {
time.Sleep(time.Millisecond * 100)
}

close(it.findPeersResult)
return nil
}

0 comments on commit 8ca4d19

Please sign in to comment.