forked from TrueCloudLab/rclone
fs/accounting: Added StatsInfo locking in statsGroups sum function (#3844)
Without the fix we can have a race, example: ``` Write at 0x00c000432039 by goroutine 187: github.com/rclone/rclone/fs/accounting.(*StatsInfo).Error() fs/accounting/stats.go:495 +0x3f1 github.com/rclone/rclone/fs/accounting.(*StatsInfo).Error-fm() fs/accounting/stats.go:477 +0x55 github.com/rclone/rclone/fs/walk.listRwalk.func1() fs/walk/walk.go:162 +0xd2 github.com/rclone/rclone/fs/walk.walk.func2() fs/walk/walk.go:402 +0x30f Previous read at 0x00c000432039 by goroutine 184: github.com/rclone/rclone/fs/accounting.(*statsGroups).sum() fs/accounting/stats_groups.go:351 +0xcae github.com/rclone/rclone/fs/accounting.rcTransferredStats() fs/accounting/stats_groups.go:132 +0x1f4 ``` Fixes #3844
This commit is contained in:
parent
7e6fac8b1e
commit
eb10ac346f
1 changed files with 18 additions and 13 deletions
|
@ -344,22 +344,27 @@ func (sg *statsGroups) names() []string {
|
||||||
func (sg *statsGroups) sum() *StatsInfo {
|
func (sg *statsGroups) sum() *StatsInfo {
|
||||||
sg.mu.Lock()
|
sg.mu.Lock()
|
||||||
defer sg.mu.Unlock()
|
defer sg.mu.Unlock()
|
||||||
|
|
||||||
sum := NewStats()
|
sum := NewStats()
|
||||||
for _, stats := range sg.m {
|
for _, stats := range sg.m {
|
||||||
sum.bytes += stats.bytes
|
stats.mu.RLock()
|
||||||
sum.errors += stats.errors
|
{
|
||||||
sum.fatalError = sum.fatalError || stats.fatalError
|
sum.bytes += stats.bytes
|
||||||
sum.retryError = sum.retryError || stats.retryError
|
sum.errors += stats.errors
|
||||||
sum.checks += stats.checks
|
sum.fatalError = sum.fatalError || stats.fatalError
|
||||||
sum.transfers += stats.transfers
|
sum.retryError = sum.retryError || stats.retryError
|
||||||
sum.deletes += stats.deletes
|
sum.checks += stats.checks
|
||||||
sum.checking.merge(stats.checking)
|
sum.transfers += stats.transfers
|
||||||
sum.transferring.merge(stats.transferring)
|
sum.deletes += stats.deletes
|
||||||
sum.inProgress.merge(stats.inProgress)
|
sum.checking.merge(stats.checking)
|
||||||
if sum.lastError == nil && stats.lastError != nil {
|
sum.transferring.merge(stats.transferring)
|
||||||
sum.lastError = stats.lastError
|
sum.inProgress.merge(stats.inProgress)
|
||||||
|
if sum.lastError == nil && stats.lastError != nil {
|
||||||
|
sum.lastError = stats.lastError
|
||||||
|
}
|
||||||
|
sum.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...)
|
||||||
}
|
}
|
||||||
sum.startedTransfers = append(sum.startedTransfers, stats.startedTransfers...)
|
stats.mu.RUnlock()
|
||||||
}
|
}
|
||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue