diff --git a/lib/blockstore/badger/blockstore.go b/lib/blockstore/badger/blockstore.go index aa57b5cae..fa9d55bdb 100644 --- a/lib/blockstore/badger/blockstore.go +++ b/lib/blockstore/badger/blockstore.go @@ -359,7 +359,11 @@ func (b *Blockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { buf = make([]byte, reqlen) } if n, err := base32.RawStdEncoding.Decode(buf, k); err == nil { - ch <- cid.NewCidV1(cid.Raw, buf[:n]) + select { + case ch <- cid.NewCidV1(cid.Raw, buf[:n]): + case <-ctx.Done(): + return + } } else { log.Warnf("failed to decode key %s in badger AllKeysChan; err: %s", k, err) } diff --git a/lib/blockstore/badger/blockstore_test_suite.go b/lib/blockstore/badger/blockstore_test_suite.go index e9eed18f5..b11fc4e23 100644 --- a/lib/blockstore/badger/blockstore_test_suite.go +++ b/lib/blockstore/badger/blockstore_test_suite.go @@ -219,6 +219,9 @@ func (s *Suite) TestReopenPutGet(t *testing.T) { fetched, err := bs.Get(orig.Cid()) require.NoError(t, err) require.Equal(t, orig.RawData(), fetched.RawData()) + + err = bs.(io.Closer).Close() + require.NoError(t, err) } func (s *Suite) TestPutMany(t *testing.T) {