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

gui: join Wait goroutines on shutdown

Nick Craig-Wood5f791079fc33
diff --git a/cmd/gui/gui.go b/cmd/gui/gui.go
index fbe03bc38..227d66ec5 100644
--- a/cmd/gui/gui.go
+++ b/cmd/gui/gui.go
@@ -11,6 +11,7 @@ import (
"net/url"
"os"
"strings"
+ "sync"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
@@ -201,14 +202,18 @@ Use --no-auth to disable authentication entirely:
}
}
- // Wait for either server to exit, then shut both down
+ // Wait for either server to exit, then shut both down and
+ // join the second goroutine before returning.
defer systemd.Notify()()
+ var wg sync.WaitGroup
done := make(chan struct{}, 2)
- go func() { rcServer.Wait(); done <- struct{}{} }()
- go func() { guiServer.Wait(); done <- struct{}{} }()
+ wg.Add(2)
+ go func() { defer wg.Done(); rcServer.Wait(); done <- struct{}{} }()
+ go func() { defer wg.Done(); guiServer.Wait(); done <- struct{}{} }()
<-done
_ = rcServer.Shutdown()
_ = guiServer.Shutdown()
+ wg.Wait()
return nil
},
}