diff --git a/CHANGELOG.md b/CHANGELOG.md index 87a33f260..a7951b656 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,7 +129,8 @@ The following emojis are used to highlight certain changes: ### Fixed -- `unixfs/hamt` Log error instead of panic if both link and shard are nil [#393](https://github.com/ipfs/boxo/pull/393) +- `unixfs/hamt`: Log error instead of panic if both link and shard are nil [#393](https://github.com/ipfs/boxo/pull/393) +- `pinner/dspinner`: do not hang when listing keys and the `out` channel is no longer read [#727](https://github.com/ipfs/boxo/pull/727) ### Security diff --git a/pinning/pinner/dspinner/pin.go b/pinning/pinner/dspinner/pin.go index bc1f61902..ddc93c2c5 100644 --- a/pinning/pinner/dspinner/pin.go +++ b/pinning/pinner/dspinner/pin.go @@ -707,11 +707,19 @@ func (p *pinner) streamIndex(ctx context.Context, index dsindex.Indexer, detaile defer p.lock.RUnlock() cidSet := cid.NewSet() + send := func(sp ipfspinner.StreamedPin) (ok bool) { + select { + case <-ctx.Done(): + return false + case out <- sp: + return true + } + } err := index.ForEach(ctx, "", func(key, value string) bool { c, err := cid.Cast([]byte(key)) if err != nil { - out <- ipfspinner.StreamedPin{Err: err} + send(ipfspinner.StreamedPin{Err: err}) return false } @@ -719,7 +727,7 @@ func (p *pinner) streamIndex(ctx context.Context, index dsindex.Indexer, detaile if detailed { pp, err := p.loadPin(ctx, value) if err != nil { - out <- ipfspinner.StreamedPin{Err: err} + send(ipfspinner.StreamedPin{Err: err}) return false } @@ -731,17 +739,16 @@ func (p *pinner) streamIndex(ctx context.Context, index dsindex.Indexer, detaile } if !cidSet.Has(c) { - select { - case <-ctx.Done(): + if !send(ipfspinner.StreamedPin{Pin: pin}) { return false - case out <- ipfspinner.StreamedPin{Pin: pin}: } cidSet.Add(c) } return true }) if err != nil { - out <- ipfspinner.StreamedPin{Err: err} + send(ipfspinner.StreamedPin{Err: err}) + return } }()