Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set context timeout for queryPeer #996

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@ -145,6 +147,8 @@
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 151 in crawler/crawler.go

View check run for this annotation

Codecov / codecov/patch

crawler/crawler.go#L150-L151

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