From 8ca4d194f0637b0ed25b34a26b7b900134336a91 Mon Sep 17 00:00:00 2001 From: Daniel N <2color@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:32:18 +0100 Subject: [PATCH] fix: bug from closing the iterator twice no need to close the channel. just the source iterator --- server_cached_router.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/server_cached_router.go b/server_cached_router.go index 3764b48..2f638f3 100644 --- a/server_cached_router.go +++ b/server_cached_router.go @@ -64,13 +64,6 @@ func (r cachedRouter) FindProviders(ctx context.Context, key cid.Cid, limit int) } 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 } @@ -199,6 +192,10 @@ func (it *cacheFallbackIter) Val() iter.Result[types.Record] { return iter.Result[types.Record]{Err: errNoValueAvailable} } +func (it *cacheFallbackIter) Close() error { + return it.sourceIter.Close() +} + func (it *cacheFallbackIter) dispatchFindPeer(record types.PeerRecord) { defer it.ongoingLookups.Add(-1) @@ -231,12 +228,3 @@ func (it *cacheFallbackIter) dispatchFindPeer(record types.PeerRecord) { it.findPeersResult <- record // pass back the record with no addrs } } - -func (it *cacheFallbackIter) Close() error { - for it.ongoingLookups.Load() > 0 { - time.Sleep(time.Millisecond * 100) - } - - close(it.findPeersResult) - return nil -}