From f681beb3355ee9628c259996f8de15f100fe6667 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/buildengine/deploy.go b/buildengine/deploy.go index 767918cb46..f76a05e506 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,19 @@ 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, diffErr := client.GetArtefactDiffs(ctx, connect.NewRequest(&ftlv1.GetArtefactDiffsRequest{ClientDigests: maps.Keys(filesByHash)})) + if diffErr != nil { + return fmt.Errorf("failed to get artefact diffs: %w after upload failure %w", diffErr, err) + } + if goslices.Contains(newDiffs.Msg.MissingDigests, missing) { + // It is still missing, return the error + return fmt.Errorf("failed to upload artifacts %w", 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) }