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

engine: add inactivity timeout for image pulling #1290

Merged
merged 1 commit into from
Mar 20, 2018
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
5 changes: 5 additions & 0 deletions agent/engine/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions agent/engine/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down