-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Explicitly Close() obj after ReadFull() #552
Conversation
Hey, thanks for giving this a try! |
// This may not read the whole object, so ensure object | ||
// is closed to avoid duplicate connections. | ||
n, err := io.ReadFull(obj, p) | ||
obj.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This discards the error that Close()
may have returned. What do you think about returning the error from Close()
in case ReadFull()
did not return any error?
Signed-off-by: Ben Agricola <bagricola@squiz.co.uk>
f6f7b7a
to
edb1843
Compare
// is closed to avoid duplicate connections. | ||
n, err := io.ReadFull(obj, p) | ||
if err != nil { | ||
obj.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume in this situation that the important part is the Read error rather than the close error.
I wonder if it's possible for a Read error to cause obj
to be already-closed, in which case this would throw an error attempting to close it twice...
Also one thing to note, there's been a number of changes to |
Yes, I agree. Thanks for your contribution! |
Explicitly Close() obj after ReadFull()
Restic makes heavy use of short reads from S3 when performing incremental backups. It runs
GetObject
fromminio-go
and reads part of the returned stream (e.g. 45 bytes from a specific offset) and then returns.This leaves the HTTP connection managed by
minio-go
containing unread data, and in this situation theminio-go
library will create a new connection for subsequent requests even though restic is finished with the previous object. Performing an incremental backup of a 7GiB filesystem I noticed connection counts from Restic to the S3 endpoint of up to 30,000 when the open file limit was raised high enough to allow this.Explicitly calling
Close()
afterio.ReadFull()
causes the remaining data to be discarded and allowsminio-go
to handle connection reuse effectively. The same incremental backup described above will use on average 15 to 30 connections for the duration of the backup.