Skip to content

Commit

Permalink
fix: possible race on artefact upload
Browse files Browse the repository at this point in the history
fixes: #2367
  • Loading branch information
stuartwdouglas committed Aug 14, 2024
1 parent acb7f5d commit 8d24de5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion buildengine/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8d24de5

Please sign in to comment.