diff --git a/crawler/crawler.go b/crawler/crawler.go index e055c541..1dcfcfa8 100644 --- a/crawler/crawler.go +++ b/crawler/crawler.go @@ -34,6 +34,7 @@ type ( DefaultCrawler struct { parallelism int connectTimeout time.Duration + queryTimeout time.Duration host host.Host dhtRPC *pb.ProtocolMessenger dialAddressExtendDur time.Duration @@ -60,6 +61,7 @@ func NewDefaultCrawler(host host.Host, opts ...Option) (*DefaultCrawler, error) return &DefaultCrawler{ parallelism: o.parallelism, connectTimeout: o.connectTimeout, + queryTimeout: 3 * o.connectTimeout, host: host, dhtRPC: pm, dialAddressExtendDur: o.dialAddressExtendDur, @@ -144,6 +146,8 @@ func (c *DefaultCrawler) Run(ctx context.Context, startingPeers []*peer.AddrInfo for i := 0; i < c.parallelism; i++ { go func() { defer wg.Done() + ctx, cancel := context.WithTimeout(ctx, c.queryTimeout) + defer cancel() for p := range jobs { res := c.queryPeer(ctx, p) results <- res