Unverified 提交 99628170 作者: Steven Allen 提交者: GitHub

Merge pull request #5453 from overbool/fix/pin/goroutine-leaks

fix(pin): goroutine leaks
...@@ -58,7 +58,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -58,7 +58,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
gcs, err := ColoredSet(ctx, pn, ds, bestEffortRoots, output) gcs, err := ColoredSet(ctx, pn, ds, bestEffortRoots, output)
if err != nil { if err != nil {
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return return
} }
emark.Append(logging.LoggableMap{ emark.Append(logging.LoggableMap{
...@@ -69,7 +72,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -69,7 +72,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
keychan, err := bs.AllKeysChan(ctx) keychan, err := bs.AllKeysChan(ctx)
if err != nil { if err != nil {
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return return
} }
...@@ -108,7 +114,11 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -108,7 +114,11 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
}) })
esweep.Done() esweep.Done()
if errors { if errors {
output <- Result{Error: ErrCannotDeleteSomeBlocks} select {
case output <- Result{Error: ErrCannotDeleteSomeBlocks}:
case <-ctx.Done():
return
}
} }
defer log.EventBegin(ctx, "GC.datastore").Done() defer log.EventBegin(ctx, "GC.datastore").Done()
...@@ -119,7 +129,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -119,7 +129,10 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
err = gds.CollectGarbage() err = gds.CollectGarbage()
if err != nil { if err != nil {
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
}
return return
} }
}() }()
...@@ -177,28 +190,44 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo ...@@ -177,28 +190,44 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
links, err := ipld.GetLinks(ctx, ng, cid) links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil { if err != nil {
errors = true errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}} select {
case output <- Result{Error: &CannotFetchLinksError{cid, err}}:
case <-ctx.Done():
return nil, ctx.Err()
}
} }
return links, nil return links, nil
} }
err := Descendants(ctx, getLinks, gcs, pn.RecursiveKeys()) err := Descendants(ctx, getLinks, gcs, pn.RecursiveKeys())
if err != nil { if err != nil {
errors = true errors = true
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
return nil, ctx.Err()
}
} }
bestEffortGetLinks := func(ctx context.Context, cid cid.Cid) ([]*ipld.Link, error) { bestEffortGetLinks := func(ctx context.Context, cid cid.Cid) ([]*ipld.Link, error) {
links, err := ipld.GetLinks(ctx, ng, cid) links, err := ipld.GetLinks(ctx, ng, cid)
if err != nil && err != ipld.ErrNotFound { if err != nil && err != ipld.ErrNotFound {
errors = true errors = true
output <- Result{Error: &CannotFetchLinksError{cid, err}} select {
case output <- Result{Error: &CannotFetchLinksError{cid, err}}:
case <-ctx.Done():
return nil, ctx.Err()
}
} }
return links, nil return links, nil
} }
err = Descendants(ctx, bestEffortGetLinks, gcs, bestEffortRoots) err = Descendants(ctx, bestEffortGetLinks, gcs, bestEffortRoots)
if err != nil { if err != nil {
errors = true errors = true
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
return nil, ctx.Err()
}
} }
for _, k := range pn.DirectKeys() { for _, k := range pn.DirectKeys() {
...@@ -208,7 +237,11 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo ...@@ -208,7 +237,11 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
err = Descendants(ctx, getLinks, gcs, pn.InternalPins()) err = Descendants(ctx, getLinks, gcs, pn.InternalPins())
if err != nil { if err != nil {
errors = true errors = true
output <- Result{Error: err} select {
case output <- Result{Error: err}:
case <-ctx.Done():
return nil, ctx.Err()
}
} }
if errors { if errors {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论