Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pin): goroutine leaks #5453

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn

gcs, err := ColoredSet(ctx, pn, ds, bestEffortRoots, output)
if err != nil {
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return
}
emark.Append(logging.LoggableMap{
Expand All @@ -69,7 +72,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn

keychan, err := bs.AllKeysChan(ctx)
if err != nil {
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return
}

Expand Down Expand Up @@ -108,7 +114,11 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
})
esweep.Done()
if errors {
output <- Result{Error: ErrCannotDeleteSomeBlocks}
select {
case output <- Result{Error: ErrCannotDeleteSomeBlocks}:
case <-ctx.Done():
return
}
}

defer log.EventBegin(ctx, "GC.datastore").Done()
Expand All @@ -119,7 +129,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn

err = gds.CollectGarbage()
if err != nil {
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return
}
}()
Expand Down Expand Up @@ -177,28 +190,44 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil {
errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}}
select {
case output <- Result{Error: &CannotFetchLinksError{cid, err}}:
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return ctx.Err() (so we know we didn't actually finish).

return nil, ctx.Err()
}
}
return links, nil
}
err := Descendants(ctx, getLinks, gcs, pn.RecursiveKeys())
if err != nil {
errors = true
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

return nil, ctx.Err()
}
}

bestEffortGetLinks := func(ctx context.Context, cid cid.Cid) ([]*ipld.Link, error) {
links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil && err != ipld.ErrNotFound {
errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}}
select {
case output <- Result{Error: &CannotFetchLinksError{cid, err}}:
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

return nil, ctx.Err()
}
}
return links, nil
}
err = Descendants(ctx, bestEffortGetLinks, gcs, bestEffortRoots)
if err != nil {
errors = true
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

return nil, ctx.Err()
}
}

for _, k := range pn.DirectKeys() {
Expand All @@ -208,7 +237,11 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
err = Descendants(ctx, getLinks, gcs, pn.InternalPins())
if err != nil {
errors = true
output <- Result{Error: err}
select {
case output <- Result{Error: err}:
case <-ctx.Done():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

return nil, ctx.Err()
}
}

if errors {
Expand Down