From 223cae0f9c444b2e8bd3ca1e0f4105f85a1c81af 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. fixes #6279 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 3a75efab6cb..46e3f2f4b69 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 12b0fadb229..bf8b7b10fa1 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()