Skip to content

Commit

Permalink
Add retries for docker network remove
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed Aug 5, 2024
1 parent 56f4bf5 commit b44f845
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strconv"
"time"

"github.com/BurntSushi/toml"
"github.com/buildpacks/lifecycle/api"
Expand Down Expand Up @@ -164,6 +165,8 @@ func (l *LifecycleExecution) PrevImageName() string {
return l.opts.PreviousImage
}

const maxNetworkRemoveRetries = 2

func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseFactoryCreator) error {
phaseFactory := phaseFactoryCreator(l)

Expand Down Expand Up @@ -219,7 +222,13 @@ func (l *LifecycleExecution) Run(ctx context.Context, phaseFactoryCreator PhaseF
return fmt.Errorf("failed to create ephemeral %s network: %w", driver, err)
}
defer func() {
_ = l.docker.NetworkRemove(ctx, networkName)
for i := 0; i <= maxNetworkRemoveRetries; i++ {
time.Sleep(100 * time.Duration(i) * time.Millisecond) // wait if retrying
if err = l.docker.NetworkRemove(ctx, networkName); err != nil {
continue

Check warning on line 228 in internal/build/lifecycle_execution.go

View check run for this annotation

Codecov / codecov/patch

internal/build/lifecycle_execution.go#L228

Added line #L228 was not covered by tests
}
break
}
}()
l.logger.Debugf("Created ephemeral bridge network %s with ID %s", networkName, resp.ID)
if resp.Warning != "" {
Expand Down

0 comments on commit b44f845

Please sign in to comment.