accounting: fix data race in Transferred()

startedTransfers is accessed by multiple threads, and it wasn't
protected by the mutex call in Transferred() func.

Fixes #4799
This commit is contained in:
Maciej Zimnoch 2020-11-26 23:54:38 +01:00 committed by GitHub
parent 9d574c0d63
commit 70e8b11805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -351,6 +351,8 @@ func (s *StatsInfo) String() string {
// Transferred returns list of all completed transfers including checked and // Transferred returns list of all completed transfers including checked and
// failed ones. // failed ones.
func (s *StatsInfo) Transferred() []TransferSnapshot { func (s *StatsInfo) Transferred() []TransferSnapshot {
s.mu.RLock()
defer s.mu.RUnlock()
ts := make([]TransferSnapshot, 0, len(s.startedTransfers)) ts := make([]TransferSnapshot, 0, len(s.startedTransfers))
for _, tr := range s.startedTransfers { for _, tr := range s.startedTransfers {