Skip to content

Commit

Permalink
Merge pull request #552 from benagricola/fix-connection-leak
Browse files Browse the repository at this point in the history
Explicitly Close() obj after ReadFull()
  • Loading branch information
fd0 committed Jul 29, 2016
2 parents e1960ca + edb1843 commit a9729ee
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/restic/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,17 @@ func (be s3) Load(h backend.Handle, p []byte, off int64) (int, error) {
defer func() {
be.connChan <- struct{}{}
}()
return io.ReadFull(obj, p)

// This may not read the whole object, so ensure object
// is closed to avoid duplicate connections.
n, err := io.ReadFull(obj, p)
if err != nil {
obj.Close()
} else {
err = obj.Close()
}
return n, err

}

// Save stores data in the backend at the handle.
Expand Down

0 comments on commit a9729ee

Please sign in to comment.