Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update retry strategy for manifest pulls to help setups that depend on network pause container for repo calls #4289

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions agent/dockerclient/dockerapi/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ const (
// output will be suppressed in debug mode
pullStatusSuppressDelay = 2 * time.Second

// Retry settings for pulling manifests.
//
// First few retries are quick (starting with 10ms) but the backoff increases
// fast (with a multiplier of 3 capping at 5s). This is to help setups that depend on
// network pause container for communicating to image repositories which require the pause
// container to be initialized before it is ready to serve requests.
// A proper long term solution is for the pause container to have a health check and Agent to
// wait for it to become healthy but until then we are relying on this retry strategy.
maximumManifestPullRetries = 9
minimumManifestPullRetryDelay = 10 * time.Millisecond
maximumManifestPullRetryDelay = 5 * time.Second
manifestPullRetryDelayMultiplier = 3
manifestPullRetryJitterMultiplier = 0.2

// retry settings for pulling images
maximumPullRetries = 5
minimumPullRetryDelay = 1100 * time.Millisecond
Expand Down Expand Up @@ -325,8 +339,8 @@ func NewDockerGoClient(sdkclientFactory sdkclientfactory.Factory,
context: ctx,
imagePullBackoff: retry.NewExponentialBackoff(minimumPullRetryDelay, maximumPullRetryDelay,
pullRetryJitterMultiplier, pullRetryDelayMultiplier),
manifestPullBackoff: retry.NewExponentialBackoff(minimumPullRetryDelay, maximumPullRetryDelay,
pullRetryJitterMultiplier, pullRetryDelayMultiplier),
manifestPullBackoff: retry.NewExponentialBackoff(minimumManifestPullRetryDelay,
maximumManifestPullRetryDelay, manifestPullRetryJitterMultiplier, manifestPullRetryDelayMultiplier),
imageTagBackoff: retry.NewConstantBackoff(tagImageRetryInterval),
inactivityTimeoutHandler: handleInactivityTimeout,
}, nil
Expand Down Expand Up @@ -372,7 +386,7 @@ func (dg *dockerGoClient) PullImageManifest(
// Call DistributionInspect API with retries
startTime := time.Now()
var distInspectPtr *registry.DistributionInspect
err = retry.RetryNWithBackoffCtx(ctx, dg.manifestPullBackoff, maximumPullRetries, func() error {
err = retry.RetryNWithBackoffCtx(ctx, dg.manifestPullBackoff, maximumManifestPullRetries, func() error {
distInspect, err := client.DistributionInspect(ctx, imageRef, encodedAuth)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func TestPullImageManifest(t *testing.T) {
client.EXPECT().
DistributionInspect(
gomock.Any(), "image", base64.URLEncoding.EncodeToString([]byte("{}"))).
Times(maximumPullRetries).
Times(maximumManifestPullRetries).
Return(
registry.DistributionInspect{},
errors.New("Some error for https://prod-us-east-1-starport-layer-bucket.s3.us-east-1.amazonaws.com"))
Expand Down
Loading