Skip to content

Improve pull handling - #1320

Merged
rnorth merged 14 commits into
masterfrom
improve-pull-callback
Jul 22, 2019
Merged

Improve pull handling#1320
rnorth merged 14 commits into
masterfrom
improve-pull-callback

Conversation

@rnorth

@rnorth rnorth commented Mar 18, 2019

Copy link
Copy Markdown
Member

Pulling of images is something that I feel we can generally improve. This PR attempts to:

  • Remove the current fixed timeout+retries for pulls, replacing it with a monitor of progress. If the download pauses for more than 30s, the pull will be aborted, but otherwise any duration of pull is allowed as long as progress is being made.

  • Make the logging more human friendly; we'll actually log the downloaded/extracted state of the layers - in a form that is informative but not too noisy in the logs.

An example of the logs from both of these changes together (where I cut the network connection during the pull):

19:34:25.198 INFO  🐳 [ibmcom/db2express-c:latest] - Pulling image
19:34:25.198 INFO  🐳 [ibmcom/db2express-c:latest] - Pulling image layers:  0 pending,  0 downloaded,  0 extracted, (0 bytes/0 bytes)
19:34:25.967 INFO  🐳 [ibmcom/db2express-c:latest] - Pulling image layers: 12 pending,  1 downloaded,  0 extracted, (32 bytes/? MB)
19:34:27.363 INFO  🐳 [ibmcom/db2express-c:latest] - Pulling image layers: 11 pending,  2 downloaded,  0 extracted, (1 MB/? MB)
19:34:58.519 ERROR 🐳 [ibmcom/db2express-c:latest] - Docker image pull has not made progress in 30s - aborting pull
19:34:58.564 ERROR 🐳 [ibmcom/db2express-c:latest] - Failed to pull image: ibmcom/db2express-c:latest. Please check output of `docker pull ibmcom/db2express-c:latest`

@rnorth
rnorth requested review from bsideup and kiview as code owners March 18, 2019 20:10
@rnorth
rnorth force-pushed the improve-pull-callback branch from 4c7f395 to 45eb617 Compare March 18, 2019 20:12
Comment thread core/src/main/java/org/testcontainers/images/LoggedPullImageResultCallback.java Outdated
Comment thread core/src/main/java/org/testcontainers/images/LoggedPullImageResultCallback.java Outdated
Comment thread core/src/main/java/org/testcontainers/images/RemoteDockerImage.java Outdated
@bsideup

bsideup commented Apr 28, 2019

Copy link
Copy Markdown
Member

Wow, really great change! 👍 Seems to make our pulling process much more stable 💯 I just left a few comments, but I really like the idea in general

logger.info("Pulling docker image: {}. Please be patient; this may take some time but only needs to be done once.", imageName);
}

if (attempts++ >= 3) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you removed the retrying logic here. Is it really safe?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is deliberate. I don't think that we have any more reasons to retry pulls.

A pull timeout was one case where a retry actually used to be useful, in that we could expect huge/slow downloads to maybe fail on the first attempt but succeed after that due to cached layers.

With the new code, we can now tolerate extremely long downloads as long as progress is being made. We shouldn't need to retry downloads because of these any more.

Other reasons for failure, such as unavailable images or auth failures make no sense to retry anyway.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave this comment unresolved for easy visiblity should we ever regret this change!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out I was wrong; I've noticed numerous failures in CI due to timeout errors at pull time.

Will reinstate retry logic for pulls!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1712

Comment thread core/src/main/java/org/testcontainers/containers/GenericContainer.java Outdated

@bsideup bsideup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍
Left a few question about the retrying mechanism, but other than that - good to go 👍

@rnorth rnorth changed the title WIP: Improve pull handling Improve pull handling Jul 21, 2019
@rnorth rnorth added this to the next milestone Jul 21, 2019
@rnorth rnorth self-assigned this Jul 21, 2019
@rnorth
rnorth force-pushed the improve-pull-callback branch from 02df4e1 to 315bc9d Compare July 21, 2019 19:09
@rnorth

rnorth commented Jul 22, 2019

Copy link
Copy Markdown
Member Author

I think I may revert 1d40670 and 315bc9d - I think the costs outweigh the benefit.

@rnorth
rnorth force-pushed the improve-pull-callback branch from 1d40670 to 87a5d9f Compare July 22, 2019 08:25
@bsideup

bsideup commented Jul 22, 2019

Copy link
Copy Markdown
Member

@rnorth what was the cost?

@rnorth

rnorth commented Jul 22, 2019

Copy link
Copy Markdown
Member Author

It's a shame you can't see the commit!

DockerClientFactory's runInsideDocker cannot use the singleton docker client, and needs to use a specific client instance for the pull. In order to make that work, I had to introduce an DockerClient parameter to RemoteDockerImage so that it could use that provided client. It 'worked' but is extending the public API somewhere else, and feels unpleasant.

We could consider a broader refactoring, but I'm not sure that it's worth it.

@bsideup

bsideup commented Jul 22, 2019

Copy link
Copy Markdown
Member

@rnorth ok 👍

@rnorth
rnorth merged commit 4df20c2 into master Jul 22, 2019
@delete-merged-branch
delete-merged-branch Bot deleted the improve-pull-callback branch July 22, 2019 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants