Skip to content

Commit 5f79107

Browse files
committed
gui: join Wait goroutines on shutdown
1 parent 7b9ac79 commit 5f79107

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

cmd/gui/gui.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"os"
1313
"strings"
14+
"sync"
1415

1516
"github.com/rclone/rclone/cmd"
1617
"github.com/rclone/rclone/fs"
@@ -201,14 +202,18 @@ Use --no-auth to disable authentication entirely:
201202
}
202203
}
203204

204-
// Wait for either server to exit, then shut both down
205+
// Wait for either server to exit, then shut both down and
206+
// join the second goroutine before returning.
205207
defer systemd.Notify()()
208+
var wg sync.WaitGroup
206209
done := make(chan struct{}, 2)
207-
go func() { rcServer.Wait(); done <- struct{}{} }()
208-
go func() { guiServer.Wait(); done <- struct{}{} }()
210+
wg.Add(2)
211+
go func() { defer wg.Done(); rcServer.Wait(); done <- struct{}{} }()
212+
go func() { defer wg.Done(); guiServer.Wait(); done <- struct{}{} }()
209213
<-done
210214
_ = rcServer.Shutdown()
211215
_ = guiServer.Shutdown()
216+
wg.Wait()
212217
return nil
213218
},
214219
}

0 commit comments

Comments
 (0)