From 97fc3b9046b531454abc6e84199a25cc56c37250 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Thu, 18 Mar 2021 10:02:30 +0100 Subject: [PATCH] rc: avoid +Inf value for speed in core/stats (#5134) Fixes #5132 --- fs/accounting/accounting.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go index 65bbb82bb..8777447d3 100644 --- a/fs/accounting/accounting.go +++ b/fs/accounting/accounting.go @@ -214,7 +214,10 @@ func (acc *Account) averageLoop() { acc.values.mu.Lock() // Add average of last second. elapsed := now.Sub(acc.values.lpTime).Seconds() - avg := float64(acc.values.lpBytes) / elapsed + avg := 0.0 + if elapsed > 0 { + avg = float64(acc.values.lpBytes) / elapsed + } // Soft start the moving average if period < averagePeriod { period++ @@ -442,7 +445,11 @@ func (acc *Account) speed() (bps, current float64) { } // Calculate speed from first read. total := float64(time.Now().Sub(acc.values.start)) / float64(time.Second) - bps = float64(acc.values.bytes) / total + if total > 0 { + bps = float64(acc.values.bytes) / total + } else { + bps = 0.0 + } current = acc.values.avg return }