From 177195aeeb3c6d04ac54a30036651ac7f73be791 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 12 May 2020 16:20:30 +0100 Subject: [PATCH] accounting: fix race clearing stats This race was introduced by 10a6a92e524ac378 accounting: reset bytes read during copy retry --- fs/accounting/accounting.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go index 4e69681ef..36d66810f 100644 --- a/fs/accounting/accounting.go +++ b/fs/accounting/accounting.go @@ -146,12 +146,16 @@ func (acc *Account) UpdateReader(in io.ReadCloser) { acc.close = in acc.origIn = in acc.closed = false - acc.lpBytes = 0 - acc.bytes = int64(0) if withBuf { acc.WithBuffer() } acc.mu.Unlock() + + // Reset counter to stop percentage going over 100% + acc.values.mu.Lock() + acc.values.lpBytes = 0 + acc.values.bytes = 0 + acc.values.mu.Unlock() } // averageLoop calculates averages for the stats in the background