Skip to content

Commit c7009d1

Browse files
fix: set context timeout for queryPeer (#996)
Co-authored-by: Guillaume Michel <[email protected]>
1 parent 084d574 commit c7009d1

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

crawler/crawler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type (
3434
DefaultCrawler struct {
3535
parallelism int
3636
connectTimeout time.Duration
37+
queryTimeout time.Duration
3738
host host.Host
3839
dhtRPC *pb.ProtocolMessenger
3940
dialAddressExtendDur time.Duration
@@ -60,6 +61,7 @@ func NewDefaultCrawler(host host.Host, opts ...Option) (*DefaultCrawler, error)
6061
return &DefaultCrawler{
6162
parallelism: o.parallelism,
6263
connectTimeout: o.connectTimeout,
64+
queryTimeout: 3 * o.connectTimeout,
6365
host: host,
6466
dhtRPC: pm,
6567
dialAddressExtendDur: o.dialAddressExtendDur,
@@ -145,6 +147,8 @@ func (c *DefaultCrawler) Run(ctx context.Context, startingPeers []*peer.AddrInfo
145147
for i := 0; i < c.parallelism; i++ {
146148
go func() {
147149
defer wg.Done()
150+
ctx, cancel := context.WithTimeout(ctx, c.queryTimeout)
151+
defer cancel()
148152
for p := range jobs {
149153
res := c.queryPeer(ctx, p)
150154
results <- res

0 commit comments

Comments
 (0)