From dd304ede339a31c4a90de9fb17dee20d6ed68029 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sat, 4 Jul 2020 22:25:45 -0700 Subject: [PATCH] solver: fix marking already cached vertex as cancelled Signed-off-by: Tonis Tiigi --- solver/progress.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/solver/progress.go b/solver/progress.go index 14f3f5e0..0548ee3b 100644 --- a/solver/progress.go +++ b/solver/progress.go @@ -12,7 +12,7 @@ import ( ) func (j *Job) Status(ctx context.Context, ch chan *client.SolveStatus) error { - vs := &vertexStream{cache: map[digest.Digest]*client.Vertex{}} + vs := &vertexStream{cache: map[digest.Digest]*client.Vertex{}, wasCached: make(map[digest.Digest]struct{})} pr := j.pr.Reader(ctx) defer func() { if enc := vs.encore(); len(enc) > 0 { @@ -72,7 +72,8 @@ func (j *Job) Status(ctx context.Context, ch chan *client.SolveStatus) error { } type vertexStream struct { - cache map[digest.Digest]*client.Vertex + cache map[digest.Digest]*client.Vertex + wasCached map[digest.Digest]struct{} } func (vs *vertexStream) append(v client.Vertex) []*client.Vertex { @@ -91,17 +92,34 @@ func (vs *vertexStream) append(v client.Vertex) []*client.Vertex { } } } + if v.Cached { + vs.markCached(v.Digest) + } + vcopy := v return append(out, &vcopy) } +func (vs *vertexStream) markCached(dgst digest.Digest) { + if v, ok := vs.cache[dgst]; ok { + if _, ok := vs.wasCached[dgst]; !ok { + for _, inp := range v.Inputs { + vs.markCached(inp) + } + } + vs.wasCached[dgst] = struct{}{} + } +} + func (vs *vertexStream) encore() []*client.Vertex { var out []*client.Vertex for _, v := range vs.cache { if v.Started != nil && v.Completed == nil { now := time.Now() v.Completed = &now - v.Error = context.Canceled.Error() + if _, ok := vs.wasCached[v.Digest]; !ok && v.Error == "" { + v.Error = context.Canceled.Error() + } out = append(out, v) } }