@cryptotaxi247 / kubo / commits / ba383eda0

"block rm": make channel large enough to avoid blocking

Make the channel for the output of RmBlocks large enough to hold any result to avoid blocking while holding the GCLock. License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed Nov 23, 2016 at 18:00 UTC ba383eda00b282545ad1da82473a096e3cd71fa3
2 files changed +7 -5
blocks/blockstore/util/remove.go
+5 -2
@@ -27,7 +27,10 @@ type RmBlocksOpts struct {
27 Force bool
28 }
29
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))
34 go func() {
35 defer close(out)
36
@@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
50 }
51 }
52 }()
50 - return nil
53 + return out, nil
54 }
55
56 func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
core/commands/block.go
+2 -3
@@ -256,8 +256,7 @@ It takes a list of base58 encoded multihashs to remove.
256
257 cids = append(cids, c)
258 }
259 - outChan := make(chan interface{})
260 - err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{
259 + ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{
260 Quiet: quiet,
261 Force: force,
262 })
@@ -265,7 +264,7 @@ It takes a list of base58 encoded multihashs to remove.
264 res.SetError(err, cmds.ErrNormal)
265 return
266 }
268 - res.SetOutput((<-chan interface{})(outChan))
267 + res.SetOutput(ch)
268 },
269 PostRun: func(req cmds.Request, res cmds.Response) {
270 if res.Error() != nil {