From 8d847a4e942727ddc589dfb03d1bec624c45b0ff Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 25 Jan 2021 17:03:57 +0000 Subject: [PATCH] lib/atexit: fix occasional failure to unmount with CTRL-C #4957 Before this change CTRL-C could come in to exit rclone which would start the atexit actions running. The Fuse unmount then signals rclone to exit which wasn't waiting for the already running atexit actions to complete. This change makes sure that if the atexit actions are started they should be completed. --- lib/atexit/atexit.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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)() }