Fix deadline handling in runBootstrap subqueries

This commit is contained in:
Matt Joiner 2019-02-15 14:46:42 +11:00
parent f7b176604f
commit 61d3de0d41
2 changed files with 7 additions and 3 deletions

View File

@ -147,9 +147,13 @@ func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error
doQuery := func(n int, target string, f func(context.Context) error) error {
logger.Infof("Bootstrapping query (%d/%d) to %s", n, cfg.Queries, target)
ctx, cancel := context.WithTimeout(ctx, cfg.Timeout)
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.

View File

@ -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 {