From 04a866121e5493fc9e972e30760853d3a175c3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Wed, 11 Nov 2020 23:12:16 +0000 Subject: [PATCH] badger/AllKeysChan(): respect context. --- lib/blockstore/badger/blockstore.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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) }