Skip to content

Commit

Permalink
engine: add inactivity timeout for image pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
fenxiong committed Mar 14, 2018
1 parent edc3e26 commit f35fb22
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit f35fb22

Please sign in to comment.