diff --git a/agent/engine/docker_client.go b/agent/engine/docker_client.go index b344d0dca24..d69ad1dc2cf 100644 --- a/agent/engine/docker_client.go +++ b/agent/engine/docker_client.go @@ -83,6 +83,10 @@ const ( // around a docker bug which sometimes results in pulls not progressing. dockerPullBeginTimeout = 5 * time.Minute + // dockerPullInactivityTimeout is the amount of time that we will + // wait when the pulling does not progress + dockerPullInactivityTimeout = 1 * time.Minute + // pullStatusSuppressDelay controls the time where pull status progress bar // output will be suppressed in debug mode pullStatusSuppressDelay = 2 * time.Second @@ -311,6 +315,7 @@ func (dg *dockerGoClient) pullImage(image string, authData *api.RegistryAuthenti opts := docker.PullImageOptions{ Repository: repository, OutputStream: pullWriter, + InactivityTimeout: dockerPullInactivityTimeout, } timeout := dg.time().After(dockerPullBeginTimeout) // pullBegan is a channel indicating that we have seen at least one line of data on the 'OutputStream' above. diff --git a/agent/engine/docker_client_test.go b/agent/engine/docker_client_test.go index 36ea07bae5d..f139e14c476 100644 --- a/agent/engine/docker_client_test.go +++ b/agent/engine/docker_client_test.go @@ -167,6 +167,19 @@ func TestPullImageGlobalTimeout(t *testing.T) { wait.Done() } +func TestPullImageInactivityTimeout(t *testing.T) { + mockDocker, client, testTime, _, _, done := dockerClientSetup(t) + defer done() + + testTime.EXPECT().After(gomock.Any()).AnyTimes() + mockDocker.EXPECT().PullImage(&pullImageOptsMatcher{"image:latest"}, gomock.Any()).Return( + docker.ErrInactivityTimeout).Times(maximumPullRetries) // expected number of retries + + metadata := client.PullImage("image", nil) + assert.Error(t, metadata.Error, "Expected error for pull inactivity timeout") + assert.Equal(t, "CannotPullContainerError", metadata.Error.(api.NamedError).ErrorName(), "Wrong error type") +} + func TestPullImage(t *testing.T) { mockDocker, client, testTime, _, _, done := dockerClientSetup(t) defer done()