Skip to content

Calling Object.Stat after io.ReadAll(obj) makes another request #2027

@OrkhanAlikhanov

Description

@OrkhanAlikhanov

From the source code it looks like once you've made a request to read contents of the file it will set the objectStat field and will return that instead of making another request. However, when you call Stat() on the object it makes another request. Debugging showed that both isStarted and objectInfoSet are false:

if !o.isStarted || !o.objectInfoSet {

And the reason is that response.Error is io.EOF and the other parts of the code never get executed.

minio-go/api-get-object.go

Lines 321 to 323 in de1893f

if response.Error != nil {
return response, response.Error
}

obj, err := client.GetObject(ctx, "my-bucket", "my-file.txt", minio.GetObjectOptions{})
if err != nil {
	return err
}

buf, err := io.ReadAll(obj)
lockfileStat, err := lockfile.Stat() // <--- this makes another request
if err != nil {
	return err
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions