Skip to content

Commit ed28dfa

Browse files
authored
fix: race condition when deploying from concurrent jobs (#3469)
1 parent dc88d7c commit ed28dfa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/function/batch.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"strings"
10+
"time"
911

1012
"github.com/cenkalti/backoff/v4"
1113
"github.com/docker/go-units"
@@ -32,6 +34,7 @@ func (s *EdgeRuntimeAPI) UpsertFunctions(ctx context.Context, functionConfig con
3234
for _, f := range result {
3335
exists[f.Slug] = struct{}{}
3436
}
37+
policy := backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxRetries), ctx)
3538
var toUpdate []api.BulkUpdateFunctionBody
3639
OUTER:
3740
for slug, function := range functionConfig {
@@ -59,12 +62,16 @@ OUTER:
5962
}
6063
functionSize := units.HumanSize(float64(body.Len()))
6164
fmt.Fprintf(os.Stderr, "Deploying Function: %s (script size: %s)\n", slug, functionSize)
62-
policy := backoff.WithContext(backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxRetries), ctx)
63-
result, err := backoff.RetryWithData(upsert, policy)
65+
result, err := backoff.RetryNotifyWithData(upsert, policy, func(err error, d time.Duration) {
66+
if strings.Contains(err.Error(), "Duplicated function slug") {
67+
exists[slug] = struct{}{}
68+
}
69+
})
6470
if err != nil {
6571
return err
6672
}
6773
toUpdate = append(toUpdate, result)
74+
policy.Reset()
6875
}
6976
if len(toUpdate) > 1 {
7077
if resp, err := s.client.V1BulkUpdateFunctionsWithResponse(ctx, s.project, toUpdate); err != nil {

0 commit comments

Comments
 (0)