mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:11:11 +08:00
vfs: fix potential data race - Fixes #6962
This fixes a data race that was found by static analysis.
This commit is contained in:
parent
72e624c5e4
commit
e82db0b7d5
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
|
@ -222,7 +223,7 @@ func waitSequential(what string, remote string, cond *sync.Cond, maxWait time.Du
|
||||||
var (
|
var (
|
||||||
timeout = time.NewTimer(maxWait)
|
timeout = time.NewTimer(maxWait)
|
||||||
done = make(chan struct{})
|
done = make(chan struct{})
|
||||||
abort = false
|
abort = int32(0)
|
||||||
)
|
)
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
|
@ -231,14 +232,14 @@ func waitSequential(what string, remote string, cond *sync.Cond, maxWait time.Du
|
||||||
// cond.Broadcast. NB cond.L == mu
|
// cond.Broadcast. NB cond.L == mu
|
||||||
cond.L.Lock()
|
cond.L.Lock()
|
||||||
// set abort flag and give all the waiting goroutines a kick on timeout
|
// set abort flag and give all the waiting goroutines a kick on timeout
|
||||||
abort = true
|
atomic.StoreInt32(&abort, 1)
|
||||||
fs.Debugf(remote, "aborting in-sequence %s wait, off=%d", what, off)
|
fs.Debugf(remote, "aborting in-sequence %s wait, off=%d", what, off)
|
||||||
cond.Broadcast()
|
cond.Broadcast()
|
||||||
cond.L.Unlock()
|
cond.L.Unlock()
|
||||||
case <-done:
|
case <-done:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
for *poff != off && !abort {
|
for *poff != off && atomic.LoadInt32(&abort) == 0 {
|
||||||
fs.Debugf(remote, "waiting for in-sequence %s to %d for %v", what, off, maxWait)
|
fs.Debugf(remote, "waiting for in-sequence %s to %d for %v", what, off, maxWait)
|
||||||
cond.Wait()
|
cond.Wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user