From 06339afe2eac20072e529da345767b058797dbaa Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 30 Apr 2019 11:34:01 -0700 Subject: [PATCH] gc: cancel context We were canceling the context in `GarbageCollect` but some functions call `GC` directly. Move the context cancelation down to where we actually _need_ it. License: MIT Signed-off-by: Steven Allen --- core/corerepo/gc.go | 2 -- pin/gc/gc.go | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/corerepo/gc.go b/core/corerepo/gc.go index 3a75efab6cb1..46e3f2f4b691 100644 --- a/core/corerepo/gc.go +++ b/core/corerepo/gc.go @@ -84,8 +84,6 @@ func BestEffortRoots(filesRoot *mfs.Root) ([]cid.Cid, error) { } func GarbageCollect(n *core.IpfsNode, ctx context.Context) error { - ctx, cancel := context.WithCancel(ctx) - defer cancel() // in case error occurs during operation roots, err := BestEffortRoots(n.FilesRoot) if err != nil { return err diff --git a/pin/gc/gc.go b/pin/gc/gc.go index 12b0fadb2293..bf8b7b10fa10 100644 --- a/pin/gc/gc.go +++ b/pin/gc/gc.go @@ -39,6 +39,7 @@ type Result struct { // The routine then iterates over every block in the blockstore and // deletes any block that is not found in the marked set. func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn pin.Pinner, bestEffortRoots []cid.Cid) <-chan Result { + ctx, cancel := context.WithCancel(ctx) elock := log.EventBegin(ctx, "GC.lockWait") unlocker := bs.GCLock() @@ -52,6 +53,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn output := make(chan Result, 128) go func() { + defer cancel() defer close(output) defer unlocker.Unlock() defer elock.Done()