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 f681beb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 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,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)
}
Expand Down

0 comments on commit f681beb

Please sign in to comment.