1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

accounting: fix file handle leak on errors - fixes #3547

In 53a1a0e3ef we introduced a problem where if there was an
error on the file being transferred then the file was re-opened and
the old one wasn't closed.

This was partially fixed in bfbddab46b however this didn't
address the case of the old file being closed.

This is now fixed by
- marking the file as open again in UpdateReader
- moving the stopping the accounting machinery to a new method Done
This commit is contained in:
Nick Craig-Wood
2019-09-18 16:54:34 +01:00
parent 70e043e641
commit 56544bb2fd
3 changed files with 35 additions and 10 deletions

View File

@@ -124,6 +124,7 @@ func (acc *Account) UpdateReader(in io.ReadCloser) {
acc.in = in
acc.close = in
acc.origIn = in
acc.closed = false
if acc.withBuf {
acc.WithBuffer()
}
@@ -243,14 +244,20 @@ func (acc *Account) Close() error {
return nil
}
acc.closed = true
close(acc.exit)
acc.stats.inProgress.clear(acc.name)
if acc.close == nil {
return nil
}
return acc.close.Close()
}
// Done with accounting - must be called to free accounting goroutine
func (acc *Account) Done() {
acc.mu.Lock()
defer acc.mu.Unlock()
close(acc.exit)
acc.stats.inProgress.clear(acc.name)
}
// progress returns bytes read as well as the size.
// Size can be <= 0 if the size is unknown.
func (acc *Account) progress() (bytes, size int64) {