@cryptotaxi247 / kubo / commits / 223cae0f9

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 <steven@stebalien.com>

Steven Allen committed Apr 30, 2019 at 11:34 UTC 223cae0f9c444b2e8bd3ca1e0f4105f85a1c81af
2 files changed +2 -2
core/corerepo/gc.go
-2
@@ -84,8 +84,6 @@ func BestEffortRoots(filesRoot *mfs.Root) ([]cid.Cid, error) {
84 }
85
86 func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
87 - ctx, cancel := context.WithCancel(ctx)
88 - defer cancel() // in case error occurs during operation
87 roots, err := BestEffortRoots(n.FilesRoot)
88 if err != nil {
89 return err
pin/gc/gc.go
+2
@@ -39,6 +39,7 @@ type Result struct {
39 // The routine then iterates over every block in the blockstore and
40 // deletes any block that is not found in the marked set.
41 func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn pin.Pinner, bestEffortRoots []cid.Cid) <-chan Result {
42 + ctx, cancel := context.WithCancel(ctx)
43
44 elock := log.EventBegin(ctx, "GC.lockWait")
45 unlocker := bs.GCLock()
@@ -52,6 +53,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
53 output := make(chan Result, 128)
54
55 go func() {
56 + defer cancel()
57 defer close(output)
58 defer unlocker.Unlock()
59 defer elock.Done()