]> source.dussan.org Git - gitea.git/commitdiff
Avoid unexpected panic in graceful manager (#29629) (#29630)
authorwxiaoguang <wxiaoguang@gmail.com>
Wed, 6 Mar 2024 11:00:21 +0000 (19:00 +0800)
committerGitHub <noreply@github.com>
Wed, 6 Mar 2024 11:00:21 +0000 (11:00 +0000)
Backport #29629

modules/graceful/manager_unix.go
modules/graceful/manager_windows.go

index b1fd6da76dd1d7fe45d74823f001e81e5c51a3fc..67c97a6e7edd171bf20850ae268b338c0171891c 100644 (file)
@@ -118,7 +118,15 @@ func (g *Manager) start(ctx context.Context) {
                defer close(startupDone)
                // Wait till we're done getting all of the listeners and then close
                // the unused ones
-               g.createServerWaitGroup.Wait()
+               func() {
+                       // FIXME: there is a fundamental design problem of the "manager" and the "wait group".
+                       // If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
+                       // There is no clear solution besides a complete rewriting of the "manager"
+                       defer func() {
+                               _ = recover()
+                       }()
+                       g.createServerWaitGroup.Wait()
+               }()
                // Ignore the error here there's not much we can do with it
                // They're logged in the CloseProvidedListeners function
                _ = CloseProvidedListeners()
index f676f86d043799555c47fcd77ec50bdcb35996cf..6bcae9f747540ae1ba34f7adf770196ab18f09e2 100644 (file)
@@ -227,7 +227,15 @@ func (g *Manager) awaitServer(limit time.Duration) bool {
        c := make(chan struct{})
        go func() {
                defer close(c)
-               g.createServerWaitGroup.Wait()
+               func() {
+                       // FIXME: there is a fundamental design problem of the "manager" and the "wait group".
+                       // If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
+                       // There is no clear solution besides a complete rewriting of the "manager"
+                       defer func() {
+                               _ = recover()
+                       }()
+                       g.createServerWaitGroup.Wait()
+               }()
        }()
        if limit > 0 {
                select {