diff --git a/lib/atexit/atexit.go b/lib/atexit/atexit.go index d0c3b08ad..575fbeb8b 100644 --- a/lib/atexit/atexit.go +++ b/lib/atexit/atexit.go @@ -77,9 +77,10 @@ func IgnoreSignals() { // Run all the at exit functions if they haven't been run already func Run() { + // Take the lock here so we wait until all have run before returning + fnsMutex.Lock() + defer fnsMutex.Unlock() exitOnce.Do(func() { - fnsMutex.Lock() - defer fnsMutex.Unlock() for fnHandle := range fns { (*fnHandle)() }