Replace WithTimeout with WithCancel whenever possible
License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Aug 17, 2015 at 15:40 UTC
5d8e15042f361e59f729d2c8f11724d58f2c7b1e
10 files changed
+12
-23
core/commands/ls.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
"fmt"
6
"io"
7
"text/tabwriter"
8
- "time"
8
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
@@ -81,7 +80,7 @@ it contains, with the following format:
80
Links: make([]LsLink, len(dagnode.Links)),
81
}
82
for j, link := range dagnode.Links {
84
- ctx, cancel := context.WithTimeout(req.Context(), time.Minute)
83
+ ctx, cancel := context.WithCancel(req.Context())
84
defer cancel()
85
link.Node, err = link.GetNode(ctx, node.DAG)
86
if err != nil {
core/commands/unixfs/ls.go
+1
-2
@@ -6,7 +6,6 @@ import (
6
"io"
7
"sort"
8
"text/tabwriter"
9
- "time"
9
10
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
11
@@ -111,7 +110,7 @@ size is the IPFS link size.
110
links := make([]LsLink, len(merkleNode.Links))
111
output.Objects[hash].Links = links
112
for i, link := range merkleNode.Links {
114
- getCtx, cancel := context.WithTimeout(ctx, time.Minute)
113
+ getCtx, cancel := context.WithCancel(ctx)
114
defer cancel()
115
link.Node, err = link.GetNode(getCtx, node.DAG)
116
if err != nil {
core/core.go
+1
-2
@@ -321,8 +321,7 @@ func setupDiscoveryOption(d config.Discovery) DiscoveryOption {
321
func (n *IpfsNode) HandlePeerFound(p peer.PeerInfo) {
322
log.Warning("trying peer info: ", p)
323
ctx, _ := context.WithTimeout(n.Context(), time.Second*10)
324
- err := n.PeerHost.Connect(ctx, p)
325
- if err != nil {
324
+ if err := n.PeerHost.Connect(ctx, p); err != nil {
325
log.Warning("Failed to connect to peer found by discovery: ", err)
326
}
327
}
core/corerepo/pinning.go
+2
-3
@@ -15,7 +15,6 @@ package corerepo
15
16
import (
17
"fmt"
18
- "time"
18
19
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
20
@@ -42,7 +41,7 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
41
return nil, err
42
}
43
45
- ctx, cancel := context.WithTimeout(ctx, time.Minute)
44
+ ctx, cancel := context.WithCancel(ctx)
45
defer cancel()
46
err = n.Pinning.Pin(ctx, dagnode, recursive)
47
if err != nil {
@@ -74,7 +73,7 @@ func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool
73
for _, dagnode := range dagnodes {
74
k, _ := dagnode.Key()
75
77
- ctx, cancel := context.WithTimeout(ctx, time.Minute)
76
+ ctx, cancel := context.WithCancel(ctx)
77
defer cancel()
78
err := n.Pinning.Unpin(ctx, k, recursive)
79
if err != nil {
core/coreunix/add.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
"io/ioutil"
6
"os"
7
gopath "path"
8
- "time"
8
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
@@ -105,7 +104,7 @@ func addNode(n *core.IpfsNode, node *merkledag.Node) error {
104
if err := n.DAG.AddRecursive(node); err != nil { // add the file to the graph + local storage
105
return err
106
}
108
- ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
107
+ ctx, cancel := context.WithCancel(n.Context())
108
defer cancel()
109
err := n.Pinning.Pin(ctx, node, true) // ensure we keep it
110
return err
core/coreunix/metadata.go
+2
-4
@@ -1,8 +1,6 @@
1
package coreunix
2
3
import (
4
- "time"
5
-
4
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
5
6
key "github.com/ipfs/go-ipfs/blocks/key"
@@ -14,7 +12,7 @@ import (
12
func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error) {
13
ukey := key.B58KeyDecode(skey)
14
17
- ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
15
+ ctx, cancel := context.WithCancel(n.Context())
16
defer cancel()
17
nd, err := n.DAG.Get(ctx, ukey)
18
if err != nil {
@@ -44,7 +42,7 @@ func AddMetadataTo(n *core.IpfsNode, skey string, m *ft.Metadata) (string, error
42
func Metadata(n *core.IpfsNode, skey string) (*ft.Metadata, error) {
43
ukey := key.B58KeyDecode(skey)
44
47
- ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
45
+ ctx, cancel := context.WithCancel(n.Context())
46
defer cancel()
47
nd, err := n.DAG.Get(ctx, ukey)
48
if err != nil {
fuse/ipns/common.go
+1
-3
@@ -1,8 +1,6 @@
1
package ipns
2
3
import (
4
- "time"
5
-
4
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
5
6
"github.com/ipfs/go-ipfs/core"
@@ -22,7 +20,7 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
20
return err
21
}
22
25
- ctx, cancel := context.WithTimeout(n.Context(), time.Minute)
23
+ ctx, cancel := context.WithCancel(n.Context())
24
defer cancel()
25
26
err = n.Pinning.Pin(ctx, emptyDir, false)
ipnsfs/dir.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
"fmt"
6
"os"
7
"sync"
8
- "time"
8
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
@@ -140,7 +139,7 @@ func (d *Directory) childDir(name string) (*Directory, error) {
139
func (d *Directory) childFromDag(name string) (*dag.Node, error) {
140
for _, lnk := range d.node.Links {
141
if lnk.Name == name {
143
- ctx, cancel := context.WithTimeout(d.ctx, time.Minute)
142
+ ctx, cancel := context.WithCancel(d.ctx)
143
defer cancel()
144
145
return lnk.GetNode(ctx, d.fs.dserv)
path/resolver.go
+1
-1
@@ -87,7 +87,7 @@ func (s *Resolver) ResolvePathComponents(ctx context.Context, fpath Path) ([]*me
87
}
88
89
log.Debug("Resolve dag get.")
90
- ctx, cancel := context.WithTimeout(ctx, time.Minute)
90
+ ctx, cancel := context.WithCancel(ctx)
91
defer cancel()
92
nd, err := s.DAG.Get(ctx, key.Key(h))
93
if err != nil {
unixfs/mod/dagmodifier.go
+1
-2
@@ -5,7 +5,6 @@ import (
5
"errors"
6
"io"
7
"os"
8
- "time"
8
9
proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
10
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
@@ -460,7 +459,7 @@ func dagTruncate(ctx context.Context, nd *mdag.Node, size uint64, ds mdag.DAGSer
459
var modified *mdag.Node
460
ndata := new(ft.FSNode)
461
for i, lnk := range nd.Links {
463
- _ctx, cancel := context.WithTimeout(ctx, time.Minute)
462
+ _ctx, cancel := context.WithCancel(ctx)
463
defer cancel()
464
465
child, err := lnk.GetNode(ctx, ds)