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

get: Fix reading an object if its size is unknown #694

Merged
merged 1 commit into from
Jun 1, 2017

Conversation

vadmeste
Copy link
Member

Getting an object and reading it doesn't work as expected when S3 server
doesn't return the object content length. (though very rare)

Fixes #693

Copy link
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

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

In the commit message mention when the content-length is missing happens and also remove the case where GCS is specially handled for its Content-Length in the same PR.

@vadmeste

return 0, io.EOF
}
o.currOffset += offset
case 2:
// If we don't the object size, immediately return an error
Copy link
Member

Choose a reason for hiding this comment

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

"If we don't know the object size return an error for io.SeekEnd"

@vadmeste
Copy link
Member Author

All comments addressed.

harshavardhana
harshavardhana previously approved these changes May 29, 2017
api-stat.go Outdated
size, err := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
if err != nil {
// Content-Length is not valid, do not verify.
size = -1
Copy link
Contributor

Choose a reason for hiding this comment

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

The question "Why are we ignoring ParseInt error" arises in mind, previous code was better. Or you can do:

@@ -126,11 +124,12 @@ func (c Client) statObject(bucketName, objectName string, reqHeaders RequestHead
        md5sum := strings.TrimPrefix(resp.Header.Get("ETag"), "\"")
        md5sum = strings.TrimSuffix(md5sum, "\"")
 
-       // Content-Length is not valid for Google Cloud Storage, do not verify.
+       // If server does not send Content-Length then we set size to -1.
        var size int64 = -1
-       if !s3utils.IsGoogleEndpoint(c.endpointURL) {
+       lenStr := resp.Header.Get("Content-Length")
+       if lenStr != "" {
                // Parse content length.
-               size, err = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
+               size, err = strconv.ParseInt(lenStr, 10, 64)
                if err != nil {
                        return ObjectInfo{}, ErrorResponse{
                                Code:       "InternalError",

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Getting an object and reading it doesn't work as expected when S3 server
doesn't return the object content length, which happens sometimes with
Google Cloud Service.
Copy link
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

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

Tested waiting on @krishnasrinivas review.

@krishnasrinivas krishnasrinivas merged commit af02b31 into minio:master Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants