Skip to content

Remove use of pkg/pools in archive#49117

Merged
thaJeztah merged 4 commits intomoby:masterfrom
dmcgowan:archive-remove-pools
Dec 28, 2024
Merged

Remove use of pkg/pools in archive#49117
thaJeztah merged 4 commits intomoby:masterfrom
dmcgowan:archive-remove-pools

Conversation

@dmcgowan
Copy link
Member

@dmcgowan dmcgowan commented Dec 17, 2024

Removes unnecessary use of pooling and prefers use of buffer pool on copy rather than pooling bufio. In some cases the bufio was used and the pool copy was still used which unnecessarily got a buffer which would not be used.

@dmcgowan dmcgowan force-pushed the archive-remove-pools branch from 9670770 to 89996ba Compare December 18, 2024 00:56
@dmcgowan
Copy link
Member Author

Update the DecompressStream logic to match what is done in containerd, it has the buffer pool now and cleans up a case where zstd decompression was not getting Close called.

@dmcgowan
Copy link
Member Author

The previous test failures were both related to the tests erroneously relying on the bufio to fill up the read buffer while now the pipe reader may return smaller chunks. Switching to io.ReadFull when a certain number of bytes is needed is the correct way to handle that. The chrootarchive failure was caused by abandoning a tee reader then assuming the write buffer was filled, so the correct thing to do is drain the reader before using the write buffer. There seem to be a few more cases like that I need to look at but I will mark this as ready for review.

@dmcgowan dmcgowan marked this pull request as ready for review December 18, 2024 07:35
return 0, io.EOF
}
n, err = r.buf.Read(p)
if err == io.EOF {
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this leak the buffer if read fails with other errors? Couldn't this just be err != nil?

Copy link
Member

Choose a reason for hiding this comment

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

Guess this should have a closer to return the buffer

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case it will just get GC'ed. It is pointless to return to the pool on other errors since the higher level operation will end. Am I missing something else which will hold other a reference?

This implementation is intentionally the same as containerd's. We can probably unify the two, the only difference is we don't (intentionally) support xz.

@vvoland vvoland added kind/refactor PR's that refactor, or clean-up code status/2-code-review labels Dec 18, 2024
@thaJeztah
Copy link
Member

Silly question; the existing pkg/pools package had some test-coverage on those pools (although I had a quick peek at some of those, and it may be very limited). With some of these being moved internal it looks like we don't have separate coverage for their replacements, other than existing tests covering them as part of where they're used.

Will we be reducing coverage with this, or are we confident that the existing tests were already covering the functionality enough?

@dmcgowan
Copy link
Member Author

Will we be reducing coverage with this, or are we confident that the existing tests were already covering the functionality enough?

We can be confident. The pools tests weren't testing much other than just adding coverage to the pools package. From coverage perspective, everything added is used by archive tests.

@vvoland vvoland added this to the 28.0.0 milestone Dec 19, 2024
@cpuguy83
Copy link
Member

Error looks legit.

Signed-off-by: Derek McGowan <derek@mcg.dev>
After the untar errors, the reader must complete in order to fill
the buffer used by the subsequent check.

Signed-off-by: Derek McGowan <derek@mcg.dev>
Cleanup decompress logic and add a pool. The close logic should be
custom defined for each compression type since they have different
close interfaces.

Signed-off-by: Derek McGowan <derek@mcg.dev>
The use of bufio for writing without flushing can lead to an incomplete
writing of the tar and subsequent unexpected EOF when importing.

Signed-off-by: Derek McGowan <derek@mcg.dev>
@thaJeztah
Copy link
Member

I updated the docker/cli PR I had in draft to test this branch, and seeing a failure that looks related;

time="2024-12-25T10:56:00Z" level=error msg="Can't add file /var/folders/95/0ydz4d79163427j3k5crp3fh0000gn/T/cp-test-465366053/file1 to tar: open /var/folders/95/0ydz4d79163427j3k5crp3fh0000gn/T/cp-test-465366053/file1: no such file or directory"
time="2024-12-25T10:56:00Z" level=error msg="Can't close tar writer: archive/tar: missed writing 8 bytes"
--- FAIL: TestRunCopyFromContainerToFilesystem (0.01s)
    cp_test.go:85: assertion failed: error is not nil: unexpected EOF
Error: something went wrong
Error: exit status 33
Error: exit status 130
time="2024-12-25T10:56:01Z" level=error msg="Error waiting for container: removal failed"
time="2024-12-25T10:56:01Z" level=error msg="error waiting for container: no such container: non-existent-container-id"
FAIL

@thaJeztah
Copy link
Member

It also looks like docker/cli still has a direct dependency on pkg/pools, but on the PR that introduced it, it was suggested that that code should probably be moved to pkg/archive, but looks like that never happened; docker/cli#5708 (comment)

@dmcgowan
Copy link
Member Author

I updated the docker/cli PR I had in draft to test this branch, and seeing a failure that looks related;

I can look at the tests there, both the failures I found in tests here were bugs in the tests which only worked because of the large bufio not requiring flushing or discarding unread data. The unexpected EOF here was due to the test write buffering the export but not flushing it which lead to importing an incomplete tar stream. While we could manually control the chunk size in the API if need be, the tests should pass with any read chunk size.

@dmcgowan
Copy link
Member Author

@thaJeztah Opened a fix for the test, definitely looks like a bad test docker/cli#5715

@thaJeztah
Copy link
Member

Merged that fix, and tested this PR in cli, buildx and buildkit with these draft PRs, and looks like CI is happy on all of them 🎉 ;

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit f5af46d into moby:master Dec 28, 2024
@thaJeztah thaJeztah deleted the archive-remove-pools branch December 28, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

Development

Successfully merging this pull request may close these issues.

4 participants