Skip to content

services/content: fix reading a blob which is smaller than the read buffer#2221

Merged
dmcgowan merged 2 commits intocontainerd:masterfrom
AkihiroSuda:content-small-blob
Mar 26, 2018
Merged

services/content: fix reading a blob which is smaller than the read buffer#2221
dmcgowan merged 2 commits intocontainerd:masterfrom
AkihiroSuda:content-small-blob

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

The newly added test fails without this fix in services/content/service.go:

$ go test -c . && sudo ./containerd.test -test.v -test.root -test.run TestContentClient
...
    --- FAIL: TestContentClient/SmallBlob (0.02s)
        provideringester.go:62: rpc error: code = OutOfRange desc = read
past object length 6 bytes
        helpers.go:67: drwx------       4096
/tmp/content-suite-ContentClient-286788688
FAIL

Signed-off-by: Akihiro Suda [email protected]

Split from #2135

@codecov-io
Copy link
Copy Markdown

codecov-io commented Mar 22, 2018

Codecov Report

Merging #2221 into master will increase coverage by 0.11%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2221      +/-   ##
==========================================
+ Coverage   41.03%   41.14%   +0.11%     
==========================================
  Files          66       66              
  Lines        7755     7755              
==========================================
+ Hits         3182     3191       +9     
+ Misses       4071     4060      -11     
- Partials      502      504       +2
Flag Coverage Δ
#windows 41.14% <ø> (+0.11%) ⬆️
Impacted Files Coverage Δ
content/local/store.go 52.12% <0%> (+1.32%) ⬆️
content/local/readerat.go 66.66% <0%> (+66.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0c1abb...a76f230. Read the comment docs.

Comment thread content/testsuite/provideringester.go Outdated
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.

Why is this test different than all the other checks? Does this need to be exported?

Please follow the existing conventions:

  1. This does not need a new file. Please put with the other checks.
  2. Don't export the identifiers.

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.

Exposed tests inprovideringester.go is expected to be used for a type that implements ProviderIngester but does not fully implement content.Store interface.

Updated the code comment for clarity.

Comment thread services/content/service.go Outdated
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.

This is the read size.

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.

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.

updated

Comment thread services/content/service.go Outdated
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.

How can that read be satisfied? If I ask for 10 bytes and you only provide 5 bytes, we can fulfill the request. The size needs to be correct to 5 bytes. Are you sure there isn't a bug in the readerAtReader?

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.

Updated the code to let size = oi.Size - offset when offset+size > oi.Size.

Are you sure there isn't a bug in the readerAtReader?
Please refer to the below comment

@stevvooe
Copy link
Copy Markdown
Member

@AkihiroSuda I think the problem with the client code is that it is trying to read more than exists. If you correctly use io.NewSectionReader, with the size clearly called out, the service should return the right value.

If you checkout the implementation in https://golang.org/src/io/io.go?s=15311:15368#L471, you can see that the buffer is sliced to the correct size.

Comment thread content/testsuite/provideringester.go Outdated
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 suspect this test will pass if you use a SectionReader.

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.

Even with SectionReader, it fails unless the exact blob size is passed.

…uffer.

The newly added test fails without this fix in services/content/service.go:

    $ go test -c . && sudo ./containerd.test -test.v -test.root -test.run TestContentClient
    ...
        --- FAIL: TestContentClient/SmallBlob (0.02s)
            provideringester.go:62: rpc error: code = OutOfRange desc = read
    past object length 6 bytes
            helpers.go:67: drwx------       4096
    /tmp/content-suite-ContentClient-286788688
    FAIL

Signed-off-by: Akihiro Suda <[email protected]>
@stevvooe
Copy link
Copy Markdown
Member

LGTM

I pushed another commit to fix the tests.

@stevvooe stevvooe added this to the 1.1 milestone Mar 23, 2018
Comment thread content/testsuite/testsuite.go Outdated
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.

This comment no longer applies

@stevvooe stevvooe force-pushed the content-small-blob branch from c8a0fc5 to a76f230 Compare March 26, 2018 15:39
@dmcgowan
Copy link
Copy Markdown
Member

LGTM

I am going to open up another issue to fix the remote reader at. In reviewing this we did figure out that the reader at interface should be returning the number of bytes read AND an EOF in this case where more bytes are requested than exists.

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.

4 participants