Skip to content

Commit 61d3de0

Browse files
committed
Fix deadline handling in runBootstrap subqueries
1 parent f7b1766 commit 61d3de0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

dht_bootstrap.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ func (dht *IpfsDHT) runBootstrap(ctx context.Context, cfg BootstrapConfig) error
147147

148148
doQuery := func(n int, target string, f func(context.Context) error) error {
149149
logger.Infof("Bootstrapping query (%d/%d) to %s", n, cfg.Queries, target)
150-
ctx, cancel := context.WithTimeout(ctx, cfg.Timeout)
150+
queryCtx, cancel := context.WithTimeout(ctx, cfg.Timeout)
151151
defer cancel()
152-
return f(ctx)
152+
err := f(queryCtx)
153+
if err == context.DeadlineExceeded && queryCtx.Err() == context.DeadlineExceeded && ctx.Err() == nil {
154+
return nil
155+
}
156+
return err
153157
}
154158

155159
// Do all but one of the bootstrap queries as random walks.

query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (r *dhtQueryRunner) Run(ctx context.Context, peers []peer.ID) (*dhtQueryRes
168168
case <-r.proc.Closed():
169169
r.RLock()
170170
defer r.RUnlock()
171-
err = context.DeadlineExceeded
171+
err = r.runCtx.Err()
172172
}
173173

174174
if r.result != nil && r.result.success {

0 commit comments

Comments
 (0)