From ddf3f3e59c58aaaf961e407650ef15aa5ded7ec7 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 10 Jul 2018 19:31:33 -0700 Subject: [PATCH] frontend: fix two data races Signed-off-by: Tonis Tiigi --- frontend/dockerfile/forward.go | 4 ++++ solver/llbsolver/vertex.go | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/dockerfile/forward.go b/frontend/dockerfile/forward.go index 7175e297892a..be3153531509 100644 --- a/frontend/dockerfile/forward.go +++ b/frontend/dockerfile/forward.go @@ -2,6 +2,7 @@ package dockerfile import ( "context" + "sync" "github.com/moby/buildkit/cache" clienttypes "github.com/moby/buildkit/client" @@ -19,6 +20,7 @@ func llbBridgeToGatewayClient(ctx context.Context, llbBridge frontend.FrontendLL type bridgeClient struct { frontend.FrontendLLBBridge + mu sync.Mutex opts map[string]string final *ref sid string @@ -38,6 +40,7 @@ func (c *bridgeClient) Solve(ctx context.Context, req client.SolveRequest, expor return nil, err } rr := &ref{r} + c.mu.Lock() c.refs = append(c.refs, rr) if final { c.final = rr @@ -49,6 +52,7 @@ func (c *bridgeClient) Solve(ctx context.Context, req client.SolveRequest, expor } c.exporterAttr = exporterAttr } + c.mu.Unlock() return rr, nil } func (c *bridgeClient) Opts() map[string]string { diff --git a/solver/llbsolver/vertex.go b/solver/llbsolver/vertex.go index 64551caba205..bd04e1ed55f5 100644 --- a/solver/llbsolver/vertex.go +++ b/solver/llbsolver/vertex.go @@ -51,8 +51,9 @@ func WithCacheSources(cms []solver.CacheManager) LoadOpt { func RuntimePlatforms(p []specs.Platform) LoadOpt { var defaultPlatform *pb.Platform + pp := make([]specs.Platform, len(p)) for i := range p { - p[i] = platforms.Normalize(p[i]) + pp[i] = platforms.Normalize(p[i]) } return func(op *pb.Op, _ *pb.OpMetadata, opt *solver.VertexOptions) error { if op.Platform == nil { @@ -67,7 +68,7 @@ func RuntimePlatforms(p []specs.Platform) LoadOpt { } if _, ok := op.Op.(*pb.Op_Exec); ok { var found bool - for _, pp := range p { + for _, pp := range pp { if pp.OS == op.Platform.OS && pp.Architecture == op.Platform.Architecture && pp.Variant == op.Platform.Variant { found = true break