Commit f191b873 authored by Steven Allen's avatar Steven Allen

better handle context cancellations in the PBDagReader

Good: If a previous read is canceled, we cancel the preloads that the read
triggered.
Bad: Future reads at that point will fail.

This fixes that issue.

License: MIT
Signed-off-by: default avatarSteven Allen <steven@stebalien.com>
parent b5263d6a
......@@ -95,10 +95,27 @@ func (dr *PBDagReader) precalcNextBuf(ctx context.Context) error {
}
nxt, err := dr.promises[dr.linkPosition].Get(ctx)
if err != nil {
dr.promises[dr.linkPosition] = nil
switch err {
case nil:
case context.DeadlineExceeded, context.Canceled:
err = ctx.Err()
if err != nil {
return ctx.Err()
}
// In this case, the context used to *preload* the node has been canceled.
// We need to retry the load with our context and we might as
// well preload some extra nodes while we're at it.
dr.preload(ctx, dr.linkPosition)
nxt, err = dr.promises[dr.linkPosition].Get(ctx)
dr.promises[dr.linkPosition] = nil
if err != nil {
return err
}
default:
return err
}
dr.promises[dr.linkPosition] = nil
dr.linkPosition++
switch nxt := nxt.(type) {
......
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