Skip to content

Commit

Permalink
fix: Set context timeout for queryPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 23, 2024
1 parent 8170ac4 commit 21b4c47
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,

Check warning on line 64 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L64

Added line #L64 was not covered by tests
host: host,
dhtRPC: pm,
dialAddressExtendDur: o.dialAddressExtendDur,
Expand Down Expand Up @@ -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()

Check warning on line 150 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L149-L150

Added lines #L149 - L150 were not covered by tests
for p := range jobs {
res := c.queryPeer(ctx, p)
results <- res
Expand Down

0 comments on commit 21b4c47

Please sign in to comment.