From 6c206b8010920269c1416792dd4e118ff9ad714f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sat, 23 Aug 2025 16:13:03 -0400 Subject: [PATCH] util: Prevent unlikely race on easy exit Race detector hit this up once, and I can see how it would be possible. --- util/sync.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/sync.go b/util/sync.go index 11f52763..3a45d571 100644 --- a/util/sync.go +++ b/util/sync.go @@ -138,7 +138,7 @@ func (obj *EasyExit) Done(err error) { } if err != nil { // TODO: we could add a mutex, and turn this into a multierr - obj.err = err + obj.err = err // use the mutex to prevent a race on this write } obj.once.Do(func() { close(obj.exit) }) } @@ -173,7 +173,9 @@ func (obj *EasyExit) Error() error { case <-obj.exit: } obj.wg.Wait() // wait for cleanup - return obj.err + obj.mutex.Lock() + defer obj.mutex.Unlock() + return obj.err // use the mutex to prevent a race on this read } // SubscribedSignal represents a synchronized read signal. It doesn't need to be