From f681beb3355ee9628c259996f8de15f100fe6667 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 15 Aug 2024 09:04:32 +1000 Subject: [PATCH 1/2] 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) } From 5c8145fa5fd7223c84b4aabd903af9b90d786f4a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 14 Aug 2024 23:57:20 +0000 Subject: [PATCH 2/2] chore(autofmt): Automated formatting --- buildengine/deploy.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildengine/deploy.go b/buildengine/deploy.go index f76a05e506..052c5d058a 100644 --- a/buildengine/deploy.go +++ b/buildengine/deploy.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + goslices "slices" "time" "connectrpc.com/connect" @@ -19,8 +20,6 @@ import ( "github.com/TBD54566975/ftl/internal/log" "github.com/TBD54566975/ftl/internal/sha256" "github.com/TBD54566975/ftl/internal/slices" - - goslices "slices" ) type deploymentArtefact struct {