Commit 993399a1 authored by Steven Allen's avatar Steven Allen

don't treat a canceled context as a successful query

fixes #172
parent 86e37ca3
......@@ -120,8 +120,6 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...ropts.Opti
}
eip.Done()
}()
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
var cfg ropts.Options
if err := cfg.Apply(opts...); err != nil {
......@@ -280,15 +278,18 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []R
return res, nil
})
// run it!
_, err = query.Run(ctx, rtp)
if len(vals) == 0 {
if err != nil {
return nil, err
}
}
reqCtx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
_, err = query.Run(reqCtx, rtp)
return vals, nil
// We do have some values but we either ran out of peers to query or
// searched for a whole minute.
//
// We'll just call this a success.
if len(vals) > 0 && (err == routing.ErrNotFound || reqCtx.Err() == context.DeadlineExceeded) {
err = nil
}
return vals, err
}
// Provider abstraction for indirect stores.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment