mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-25 10:27:01 +08:00
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: rht <rhtbot@gmail.com>
This commit is contained in:
@ -6,8 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
|
|
||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
merkledag "github.com/ipfs/go-ipfs/merkledag"
|
||||||
@ -80,9 +78,7 @@ it contains, with the following format:
|
|||||||
Links: make([]LsLink, len(dagnode.Links)),
|
Links: make([]LsLink, len(dagnode.Links)),
|
||||||
}
|
}
|
||||||
for j, link := range dagnode.Links {
|
for j, link := range dagnode.Links {
|
||||||
ctx, cancel := context.WithCancel(req.Context())
|
link.Node, err = link.GetNode(req.Context(), node.DAG)
|
||||||
defer cancel()
|
|
||||||
link.Node, err = link.GetNode(ctx, node.DAG)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -9,10 +9,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
|
||||||
|
|
||||||
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
|
|
||||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
@ -480,14 +478,11 @@ resulting object hash.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(req.Context(), time.Second*30)
|
rnode, err := nd.DAG.Get(req.Context(), rhash)
|
||||||
rnode, err := nd.DAG.Get(ctx, rhash)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
cancel()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cancel()
|
|
||||||
|
|
||||||
action := req.Arguments()[1]
|
action := req.Arguments()[1]
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
|
|
||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
@ -110,9 +108,7 @@ size is the IPFS link size.
|
|||||||
links := make([]LsLink, len(merkleNode.Links))
|
links := make([]LsLink, len(merkleNode.Links))
|
||||||
output.Objects[hash].Links = links
|
output.Objects[hash].Links = links
|
||||||
for i, link := range merkleNode.Links {
|
for i, link := range merkleNode.Links {
|
||||||
getCtx, cancel := context.WithCancel(ctx)
|
link.Node, err = link.GetNode(ctx, node.DAG)
|
||||||
defer cancel()
|
|
||||||
link.Node, err = link.GetNode(getCtx, node.DAG)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -367,8 +367,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = i.node.DAG.AddRecursive(newnode)
|
if err := i.node.DAG.AddRecursive(newnode); err != nil {
|
||||||
if err != nil {
|
|
||||||
webError(w, "Could not add recursively new node", err, http.StatusInternalServerError)
|
webError(w, "Could not add recursively new node", err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -439,8 +438,7 @@ func (i *gatewayHandler) deleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = i.node.DAG.AddRecursive(newnode)
|
if err := i.node.DAG.AddRecursive(newnode); err != nil {
|
||||||
if err != nil {
|
|
||||||
webError(w, "Could not add recursively new node", err, http.StatusInternalServerError)
|
webError(w, "Could not add recursively new node", err, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package coreunix
|
package coreunix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
|
||||||
|
|
||||||
key "github.com/ipfs/go-ipfs/blocks/key"
|
key "github.com/ipfs/go-ipfs/blocks/key"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||||
@ -12,9 +10,7 @@ import (
|
|||||||
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
|
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
|
||||||
ukey := key.B58KeyDecode(skey)
|
ukey := key.B58KeyDecode(skey)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(n.Context())
|
nd, err := n.DAG.Get(n.Context(), ukey)
|
||||||
defer cancel()
|
|
||||||
nd, err := n.DAG.Get(ctx, ukey)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -26,8 +22,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
mdnode.Data = mdata
|
mdnode.Data = mdata
|
||||||
err = mdnode.AddNodeLinkClean("file", nd)
|
if err := mdnode.AddNodeLinkClean("file", nd); err != nil {
|
||||||
if err != nil {
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +37,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
|
|||||||
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
|
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
|
||||||
ukey := key.B58KeyDecode(skey)
|
ukey := key.B58KeyDecode(skey)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(n.Context())
|
nd, err := n.DAG.Get(n.Context(), ukey)
|
||||||
defer cancel()
|
|
||||||
nd, err := n.DAG.Get(ctx, ukey)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package trickle
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
|
|
||||||
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
|
|
||||||
@ -268,9 +267,7 @@ func verifyTDagRec(nd *dag.Node, depth, direct, layerRepeat int, ds dag.DAGServi
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(nd.Links); i++ {
|
for i := 0; i < len(nd.Links); i++ {
|
||||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute)
|
child, err := nd.Links[i].GetNode(context.TODO(), ds)
|
||||||
defer cancel()
|
|
||||||
child, err := nd.Links[i].GetNode(ctx, ds)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,10 +139,7 @@ func (d *Directory) childDir(name string) (*Directory, error) {
|
|||||||
func (d *Directory) childFromDag(name string) (*dag.Node, error) {
|
func (d *Directory) childFromDag(name string) (*dag.Node, error) {
|
||||||
for _, lnk := range d.node.Links {
|
for _, lnk := range d.node.Links {
|
||||||
if lnk.Name == name {
|
if lnk.Name == name {
|
||||||
ctx, cancel := context.WithCancel(d.ctx)
|
return lnk.GetNode(d.ctx, d.fs.dserv)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
return lnk.GetNode(ctx, d.fs.dserv)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
|||||||
|
|
||||||
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 {
|
|||||||
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
|
|||||||
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
|
||||||
|
|||||||
@ -87,8 +87,6 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*me
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Resolve dag get.")
|
log.Debug("Resolve dag get.")
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
nd, err := s.DAG.Get(ctx, key.Key(h))
|
nd, err := s.DAG.Get(ctx, key.Key(h))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -106,8 +106,7 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {
|
|||||||
|
|
||||||
p.recursePin.AddBlock(k)
|
p.recursePin.AddBlock(k)
|
||||||
} else {
|
} else {
|
||||||
_, err := p.dserv.Get(ctx, k)
|
if _, err := p.dserv.Get(ctx, k); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -459,9 +459,6 @@ func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGSer
|
|||||||
var modified *mdag.Node
|
var modified *mdag.Node
|
||||||
ndata := new(ft.FSNode)
|
ndata := new(ft.FSNode)
|
||||||
for i, lnk := range nd.Links {
|
for i, lnk := range nd.Links {
|
||||||
_ctx, cancel := context.WithCancel(ctx)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
child, err := lnk.GetNode(ctx, ds)
|
child, err := lnk.GetNode(ctx, ds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -474,7 +471,7 @@ func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGSer
|
|||||||
|
|
||||||
// found the child we want to cut
|
// found the child we want to cut
|
||||||
if size < cur+childsize {
|
if size < cur+childsize {
|
||||||
nchild, err := dagTruncate(_ctx, child, size-cur, ds)
|
nchild, err := dagTruncate(ctx, child, size-cur, ds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user