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

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

Closed
OrkhanAlikhanov opened this issue Dec 3, 2024 · 1 comment · Fixed by #2028
Closed

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

OrkhanAlikhanov opened this issue Dec 3, 2024 · 1 comment · Fixed by #2028

Comments

@OrkhanAlikhanov
Copy link
Contributor

OrkhanAlikhanov commented Dec 3, 2024

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
}
@OrkhanAlikhanov
Copy link
Contributor Author

I created a PR to convey the idea #2028

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 a pull request may close this issue.

1 participant