Skip to content

Commit

Permalink
fix: set context timeout for queryPeer (#996)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Michel <[email protected]>
  • Loading branch information
MarcoPolo and guillaumemichel authored Nov 13, 2024
1 parent 084d574 commit c7009d1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type (
DefaultCrawler struct {
parallelism int
connectTimeout time.Duration
queryTimeout time.Duration
host host.Host
dhtRPC *pb.ProtocolMessenger
dialAddressExtendDur time.Duration
Expand All @@ -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,
Expand Down Expand Up @@ -145,6 +147,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
Expand Down

0 comments on commit c7009d1

Please sign in to comment.