diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go index b4b32a8ee..fc17f95ac 100644 --- a/fs/accounting/stats.go +++ b/fs/accounting/stats.go @@ -714,10 +714,10 @@ func (s *StatsInfo) NewTransferRemoteSize(remote string, size int64) *Transfer { // DoneTransferring removes a transfer from the stats // -// if ok is true then it increments the transfers count +// if ok is true and it was in the transfermap (to avoid incrementing in case of nested calls, #6213) then it increments the transfers count func (s *StatsInfo) DoneTransferring(remote string, ok bool) { - s.transferring.del(remote) - if ok { + existed := s.transferring.del(remote) + if ok && existed { s.mu.Lock() s.transfers++ s.mu.Unlock() diff --git a/fs/accounting/transfermap.go b/fs/accounting/transfermap.go index ed64bf369..4fb30a079 100644 --- a/fs/accounting/transfermap.go +++ b/fs/accounting/transfermap.go @@ -34,10 +34,13 @@ func (tm *transferMap) add(tr *Transfer) { } // del removes a transfer from the map by name -func (tm *transferMap) del(remote string) { +func (tm *transferMap) del(remote string) bool { tm.mu.Lock() + _, exists := tm.items[remote] delete(tm.items, remote) tm.mu.Unlock() + + return exists } // merge adds items from another map