mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
Fix deadline handling in runBootstrap subqueries
This commit is contained in:
parent
f7b176604f
commit
61d3de0d41
@ -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 {
|
doQuery := func(n int, target string, f func(context.Context) error) error {
|
||||||
logger.Infof("Bootstrapping query (%d/%d) to %s", n, cfg.Queries, target)
|
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()
|
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.
|
// Do all but one of the bootstrap queries as random walks.
|
||||||
|
2
query.go
2
query.go
@ -168,7 +168,7 @@ func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryRes
|
|||||||
case <-r.proc.Closed():
|
case <-r.proc.Closed():
|
||||||
r.RLock()
|
r.RLock()
|
||||||
defer r.RUnlock()
|
defer r.RUnlock()
|
||||||
err = context.DeadlineExceeded
|
err = r.runCtx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.result != nil && r.result.success {
|
if r.result != nil && r.result.success {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user