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 ...@@ -120,8 +120,6 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...ropts.Opti
} }
eip.Done() eip.Done()
}() }()
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
var cfg ropts.Options var cfg ropts.Options
if err := cfg.Apply(opts...); err != nil { if err := cfg.Apply(opts...); err != nil {
...@@ -280,15 +278,18 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []R ...@@ -280,15 +278,18 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []R
return res, nil return res, nil
}) })
// run it! reqCtx, cancel := context.WithTimeout(ctx, time.Minute)
_, err = query.Run(ctx, rtp) defer cancel()
if len(vals) == 0 { _, err = query.Run(reqCtx, rtp)
if err != nil {
return nil, err
}
}
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. // 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