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

fix bug that gen layer tar contains duplicated files #4428

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

yyb196
Copy link
Contributor

@yyb196 yyb196 commented Nov 21, 2023

I run into a problem that randomly happen, image build and pushed by buildkit cannot be pulled by containerd or docker.

containerd complains that failed to convert whiteout file "etc/.wh.hosts": file exists: unknown.

docker complains that failed to register layer: Error processing tar file(exit status 1): archive/tar: invalid tar header,

or failed to register layer: Error processing tar file(duplicates of file paths not supported).

After dig a while, I found that layer which unpack fail contains duplicated files:
image

According to code at https://github.com/moby/buildkit/blob/master/vendor/github.com/containerd/containerd/content/local/store.go#L594 , content writer always use the already written content, this is ok for pulling content from registry, but when pushing image, content generated by snapshot comparing, in case previous cw partially write and fail, the following build will use the cached snapshot and generate layer content which append to the existing content.

In pushing case, if cw write or commit failed, we should truncate the already written file.

For guys want to know why cw write failed, there is a buildkitd log indicate the reason:

time="2023-11-20T20:14:36+08:00" level=warning msg="failed to compute blob by overlay differ (ok=false): failed to write compressed diff: mount callback failed on /tmp/containerd-mount3430795329: mount callback failed on /tmp/containerd-mount1305828223: failed to record upperdir changes (close error: failed to close tar writer: context canceled): failed to copy: context canceled"

@yyb196 yyb196 changed the title fix bug that gen layer tar contains deplicated files fix bug that gen layer tar contains duplicated files Nov 21, 2023
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

This is a good find. I think we want to call ContentStore.Abort() instead in the error handler. And cw.Truncate(0) after the Writer() call to make sure the writer is always empty(eg. no other client has used same ref).

@yyb196
Copy link
Contributor Author

yyb196 commented Nov 22, 2023

@tonistiigi have commit change as you suggested, PTALA.

@tonistiigi tonistiigi merged commit b449be8 into moby:master Nov 22, 2023
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants