From 8d24de57d3a79ebf6ff4ccaca7c48629c9f259f2 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 15 Aug 2024 09:04:32 +1000 Subject: [PATCH] fix: possible race on artefact upload fixes: #2367 --- buildengine/deploy.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/buildengine/deploy.go b/buildengine/deploy.go index 767918cb46..7bc14b9451 100644 --- a/buildengine/deploy.go +++ b/buildengine/deploy.go @@ -19,6 +19,8 @@ import ( "github.com/TBD54566975/ftl/internal/log" "github.com/TBD54566975/ftl/internal/sha256" "github.com/TBD54566975/ftl/internal/slices" + + goslices "slices" ) type deploymentArtefact struct { @@ -74,7 +76,20 @@ func Deploy(ctx context.Context, module Module, replicas int32, waitForDeployOnl Content: content, })) if err != nil { - return err + // there is a possible race here, another deployment may have uploaded it + // double check it has not been added + + newDiffs, err := client.GetArtefactDiffs(ctx, connect.NewRequest(&ftlv1.GetArtefactDiffsRequest{ClientDigests: maps.Keys(filesByHash)})) + if err != nil { + return err + } + if goslices.Contains(newDiffs.Msg.MissingDigests, missing) { + // It is still missing, return the error + return err + } else { + logger.Debugf("Upload %s of was cancelled as another deployment uploaded it", relToCWD(file.localPath)) + continue + } } logger.Debugf("Uploaded %s as %s:%s", relToCWD(file.localPath), sha256.FromBytes(resp.Msg.Digest), file.Path) }