1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 23:42:20 +08:00

Make sure ctx in commands are derived from req.Context

License: MIT
Signed-off-by: rht <rhtbot@gmail.com>
This commit is contained in:
rht
2015-08-16 18:22:40 +07:00
parent a052087974
commit d32177cda0
13 changed files with 34 additions and 62 deletions

View File

@ -320,7 +320,7 @@ func setupDiscoveryOption(d config.Discovery) DiscoveryOption {
func (n *IpfsNode) HandlePeerFound(p peer.PeerInfo) {
log.Warning("trying peer info: ", p)
ctx, _ := context.WithTimeout(context.TODO(), time.Second*10)
ctx, _ := context.WithTimeout(n.Context(), time.Second*10)
err := n.PeerHost.Connect(ctx, p)
if err != nil {
log.Warning("Failed to connect to peer found by discovery: ", err)
@ -367,6 +367,9 @@ func (n *IpfsNode) Close() error {
// Context returns the IpfsNode context
func (n *IpfsNode) Context() context.Context {
if n.ctx == nil {
n.ctx = context.TODO()
}
return n.ctx
}