Skip to content

Commit

Permalink
gc: cancel context
Browse files Browse the repository at this point in the history
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 <steven@stebalien.com>
  • Loading branch information
Stebalien committed Apr 30, 2019
1 parent 832077b commit 06339af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 0 additions & 2 deletions core/corerepo/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 06339af

Please sign in to comment.