Commit dbcf68e9 authored by rht's avatar rht

Localize the scope of context.WithCancel for every DAG.Get

Instead put it inside of DAG.Get.
The fix is applied only in the case when the context.WithCancel
before a DAG.Get is also used later on in the scope.

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent 7993a94b
...@@ -93,6 +93,8 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) { ...@@ -93,6 +93,8 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
if n == nil { if n == nil {
return nil, fmt.Errorf("dagService is nil") return nil, fmt.Errorf("dagService is nil")
} }
ctx, cancel := context.WithCancel(ctx)
defer cancel()
b, err := n.Blocks.GetBlock(ctx, k) b, err := n.Blocks.GetBlock(ctx, k)
if err != nil { if err != nil {
......
...@@ -3,7 +3,6 @@ package traverse ...@@ -3,7 +3,6 @@ package traverse
import ( import (
"errors" "errors"
"time"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context" "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
...@@ -67,10 +66,7 @@ func (t *traversal) callFunc(next State) error { ...@@ -67,10 +66,7 @@ func (t *traversal) callFunc(next State) error {
func (t *traversal) getNode(link *mdag.Link) (*mdag.Node, error) { func (t *traversal) getNode(link *mdag.Link) (*mdag.Node, error) {
getNode := func(l *mdag.Link) (*mdag.Node, error) { getNode := func(l *mdag.Link) (*mdag.Node, error) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute) next, err := l.GetNode(context.TODO(), t.opts.DAG)
defer cancel()
next, err := l.GetNode(ctx, t.opts.DAG)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -52,8 +52,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s ...@@ -52,8 +52,7 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
return nil, err return nil, err
} }
_, err = ds.Add(root) if _, err := ds.Add(root); err != nil {
if err != nil {
return nil, err return nil, err
} }
return root, nil return root, nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment