From ba383eda00b282545ad1da82473a096e3cd71fa3 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Wed, 23 Nov 2016 18:00:20 -0500 Subject: [PATCH] "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 --- blocks/blockstore/util/remove.go | 7 +++++-- core/commands/block.go | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/blocks/blockstore/util/remove.go b/blocks/blockstore/util/remove.go index 1c8f0c31e9f..b4375855bbf 100644 --- a/blocks/blockstore/util/remove.go +++ b/blocks/blockstore/util/remove.go @@ -27,7 +27,10 @@ type RmBlocksOpts struct { Force bool } -func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error { +func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) { + // make the channel large enough to hold any result to avoid + // blocking while holding the GCLock + out := make(chan interface{}, len(cids)) go func() { defer close(out) @@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c } } }() - return nil + return out, nil } func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid { diff --git a/core/commands/block.go b/core/commands/block.go index eb96dc06091..fa27b0162ca 100644 --- a/core/commands/block.go +++ b/core/commands/block.go @@ -256,8 +256,7 @@ It takes a list of base58 encoded multihashs to remove. cids = append(cids, c) } - outChan := make(chan interface{}) - err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{ + ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{ Quiet: quiet, Force: force, }) @@ -265,7 +264,7 @@ It takes a list of base58 encoded multihashs to remove. res.SetError(err, cmds.ErrNormal) return } - res.SetOutput((<-chan interface{})(outChan)) + res.SetOutput(ch) }, PostRun: func(req cmds.Request, res cmds.Response) { if res.Error() != nil {