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()