Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

vfs: fix potential data race - Fixes #6962

Nick Craig-Woode82db0b7d5b4
diff --git a/vfs/read.go b/vfs/read.go
index 53d621a3c..0fb250699 100644
--- a/vfs/read.go
+++ b/vfs/read.go
@@ -7,6 +7,7 @@ import (
"io"
"os"
"sync"
+ "sync/atomic"
"time"
"github.com/rclone/rclone/fs"
@@ -222,7 +223,7 @@ func waitSequential(what string, remote string, cond *sync.Cond, maxWait time.Du
var (
timeout = time.NewTimer(maxWait)
done = make(chan struct{})
- abort = false
+ abort = int32(0)
)
go func() {
select {
@@ -231,14 +232,14 @@ func waitSequential(what string, remote string, cond *sync.Cond, maxWait time.Du
// cond.Broadcast. NB cond.L == mu
cond.L.Lock()
// 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)
cond.Broadcast()
cond.L.Unlock()
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)
cond.Wait()
}