From d4e630c482bde6e4f6da3d2257ee6e8d9955f180 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 17 May 2024 15:00:11 -0700 Subject: [PATCH] Lock ops based on computed key rather than LLB digest --- solver/simple.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/solver/simple.go b/solver/simple.go index 274545d38..5fa347c5b 100644 --- a/solver/simple.go +++ b/solver/simple.go @@ -91,11 +91,6 @@ func (s *simpleSolver) build(ctx context.Context, job *Job, e Edge) (CachedResul } func (s *simpleSolver) buildOne(ctx context.Context, d digest.Digest, vertex Vertex, job *Job, e Edge) (Result, digest.Digest, error) { - // Ensure we don't have multiple threads working on the same digest. - wait, done := s.parallelGuard.acquire(ctx, d) - defer done() - <-wait - st := s.state(vertex, job) // Add cache opts to context as they will be accessed by cache retrieval. @@ -118,6 +113,14 @@ func (s *simpleSolver) buildOne(ctx context.Context, d digest.Digest, vertex Ver return nil, "", err } + // Ensure we don't have multiple threads working on the same operation. The + // computed cache key needs to be used here instead of the vertex + // digest. This is because the vertex can sometimes differ for the same + // operation depending on its ancestors. + wait, done := s.parallelGuard.acquire(ctx, cacheKey) + defer done() + <-wait + v, ok, err := s.resultSource.Load(ctx, cacheKey) if err != nil { return nil, "", err