From e82db0b7d5b4e9e936f5a8d0e002b54a01fd2bda Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 20 Apr 2023 17:29:07 +0100 Subject: [PATCH] vfs: fix potential data race - Fixes #6962 This fixes a data race that was found by static analysis. --- vfs/read.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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() }