Skip to content

Commit e855047

Browse files
Merge pull request ipfs#3418 from ipfs/kevina/rmblock-noblock
"block rm": make channel large enough to avoid blocking
2 parents 66315b8 + ba383ed commit e855047

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

blocks/blockstore/util/remove.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ type RmBlocksOpts struct {
2727
Force bool
2828
}
2929

30-
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error {
30+
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) {
31+
// make the channel large enough to hold any result to avoid
32+
// blocking while holding the GCLock
33+
out := make(chan interface{}, len(cids))
3134
go func() {
3235
defer close(out)
3336

@@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
4750
}
4851
}
4952
}()
50-
return nil
53+
return out, nil
5154
}
5255

5356
func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {

core/commands/block.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,15 @@ It takes a list of base58 encoded multihashs to remove.
254254

255255
cids = append(cids, c)
256256
}
257-
outChan := make(chan interface{})
258-
err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{
257+
ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{
259258
Quiet: quiet,
260259
Force: force,
261260
})
262261
if err != nil {
263262
res.SetError(err, cmds.ErrNormal)
264263
return
265264
}
266-
res.SetOutput((<-chan interface{})(outChan))
265+
res.SetOutput(ch)
267266
},
268267
PostRun: func(req cmds.Request, res cmds.Response) {
269268
if res.Error() != nil {

0 commit comments

Comments
 (0)