Skip to content

Commit

Permalink
Merge pull request #4752 from mtrmac/retry-overflow
Browse files Browse the repository at this point in the history
Fix an overflow on retries on container name conflicts
  • Loading branch information
rhatdan authored May 2, 2023
2 parents 3908816 + 4775b24 commit f353690
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions new.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
tmpName = findUnusedContainer(tmpName, containers)
}

conflict := 100
suffixDigitsModulo := 100
for {

var flags map[string]interface{}
Expand All @@ -265,8 +265,10 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
if !errors.Is(err, storage.ErrDuplicateName) || options.Container != "" {
return nil, fmt.Errorf("creating container: %w", err)
}
tmpName = fmt.Sprintf("%s-%d", name, rand.Int()%conflict)
conflict = conflict * 10
tmpName = fmt.Sprintf("%s-%d", name, rand.Int()%suffixDigitsModulo)
if suffixDigitsModulo < 1_000_000_000 {
suffixDigitsModulo *= 10
}
}
defer func() {
if err != nil {
Expand Down

0 comments on commit f353690

Please sign in to comment.