Skip to content

Commit

Permalink
Merge pull request #999 from libp2p/fix/context-from-996
Browse files Browse the repository at this point in the history
fix(crawler): separate timeout per query
  • Loading branch information
guillaumemichel authored Nov 15, 2024
2 parents f671a50 + 02e9c54 commit ace7582
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ 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)
qctx, cancel := context.WithTimeout(ctx, c.queryTimeout)
res := c.queryPeer(qctx, p)
cancel() // do not defer, cleanup after each job
results <- res
}
}()
Expand Down

0 comments on commit ace7582

Please sign in to comment.