Skip to content

Commit

Permalink
Merge pull request ipfs#264 from libp2p/run-bootstrap-deadline-exceeded
Browse files Browse the repository at this point in the history
Fix Bootstrap sub-queries
  • Loading branch information
anacrolix authored Feb 19, 2019
2 parents 5f67727 + 61d3de0 commit 7022c62
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions dht_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error
defer logger.EventBegin(ctx, "dhtRunBootstrap").Done()

doQuery := func(n int, target string, f func(context.Context) error) error {
logger.Debugf("Bootstrapping query (%d/%d) to %s", n, cfg.Queries, target)
ctx, cancel := context.WithTimeout(ctx, cfg.Timeout)
logger.Infof("Bootstrapping query (%d/%d) to %s", n, cfg.Queries, target)
queryCtx, cancel := context.WithTimeout(ctx, cfg.Timeout)
defer cancel()
return f(ctx)
err := f(queryCtx)
if err == context.DeadlineExceeded && queryCtx.Err() == context.DeadlineExceeded && ctx.Err() == nil {
return nil
}
return err
}

// Do all but one of the bootstrap queries as random walks.
Expand Down
2 changes: 1 addition & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryRes
case <-r.proc.Closed():
r.RLock()
defer r.RUnlock()
err = context.DeadlineExceeded
err = r.runCtx.Err()
}

if r.result != nil && r.result.success {
Expand Down

0 comments on commit 7022c62

Please sign in to comment.