Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 6a836d1

Browse files
committed
tweak: Add timeout to prevent lengthy query failures
This significantly reduces the time it takes to publish a record to IPNS.
1 parent 79f3790 commit 6a836d1

File tree

2 files changed

+6
-0
lines changed
  • vendor/gx/ipfs
    • QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht
    • QmdR6WN3TUEAVQ9KWE2UiFJikWTbUvgBJay6mjB4yUJebq/go-libp2p-kad-dht

2 files changed

+6
-0
lines changed

vendor/gx/ipfs/QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht/lookup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"strings"
7+
"time"
78

89
kb "gx/ipfs/QmSNE1XryoCMnZCbRaj1D23k6YKCaTQ386eJciu1pAfu8M/go-libp2p-kbucket"
910
pb "gx/ipfs/QmSY3nkMNLzh9GdbFKK5tT7YMfLpf52iUZ8ZRkr29MJaa5/go-libp2p-kad-dht/pb"
@@ -65,13 +66,15 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan pee
6566
// since the query doesnt actually pass our context down
6667
// we have to hack this here. whyrusleeping isnt a huge fan of goprocess
6768
parent := ctx
69+
ctx, _ = context.WithTimeout(ctx, time.Second*3)
6870
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
6971
// For DHT query command
7072
notif.PublishQueryEvent(parent, &notif.QueryEvent{
7173
Type: notif.SendingQuery,
7274
ID: p,
7375
})
7476

77+
ctx, _ = context.WithTimeout(ctx, time.Second*3)
7578
pmes, err := dht.findPeerSingle(ctx, p, peer.ID(key))
7679
if err != nil {
7780
logger.Debugf("error getting closer peers: %s", err)

vendor/gx/ipfs/QmdR6WN3TUEAVQ9KWE2UiFJikWTbUvgBJay6mjB4yUJebq/go-libp2p-kad-dht/lookup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"strings"
7+
"time"
78

89
kb "gx/ipfs/QmSNE1XryoCMnZCbRaj1D23k6YKCaTQ386eJciu1pAfu8M/go-libp2p-kbucket"
910
cid "gx/ipfs/QmTbxNB1NwDesLmKTscr4udL2tVP7MaxvXnD1D9yX7g3PN/go-cid"
@@ -65,13 +66,15 @@ func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan pee
6566
// since the query doesnt actually pass our context down
6667
// we have to hack this here. whyrusleeping isnt a huge fan of goprocess
6768
parent := ctx
69+
ctx, _ = context.WithTimeout(ctx, time.Second*3)
6870
query := dht.newQuery(key, func(ctx context.Context, p peer.ID) (*dhtQueryResult, error) {
6971
// For DHT query command
7072
notif.PublishQueryEvent(parent, &notif.QueryEvent{
7173
Type: notif.SendingQuery,
7274
ID: p,
7375
})
7476

77+
ctx, _ = context.WithTimeout(ctx, time.Second*3)
7578
pmes, err := dht.findPeerSingle(ctx, p, peer.ID(key))
7679
if err != nil {
7780
logger.Debugf("error getting closer peers: %s", err)

0 commit comments

Comments
 (0)