Skip to content

Commit 90a3f2d

Browse files
authored
Avoid unexpected panic in graceful manager (#29629)
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" If there are some mistakes in the app.ini, end users would just see the "panic", but not the real error messages. A real case: #27643 This PR is just a quick fix for the annoying panic problem.
1 parent c381343 commit 90a3f2d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

modules/graceful/manager_unix.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ func (g *Manager) start() {
5959
go func() {
6060
defer close(startupDone)
6161
// Wait till we're done getting all the listeners and then close the unused ones
62-
g.createServerWaitGroup.Wait()
62+
func() {
63+
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
64+
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
65+
// There is no clear solution besides a complete rewriting of the "manager"
66+
defer func() {
67+
_ = recover()
68+
}()
69+
g.createServerWaitGroup.Wait()
70+
}()
6371
// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
6472
_ = CloseProvidedListeners()
6573
g.notify(readyMsg)

modules/graceful/manager_windows.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@ func (g *Manager) awaitServer(limit time.Duration) bool {
150150
c := make(chan struct{})
151151
go func() {
152152
defer close(c)
153-
g.createServerWaitGroup.Wait()
153+
func() {
154+
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
155+
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
156+
// There is no clear solution besides a complete rewriting of the "manager"
157+
defer func() {
158+
_ = recover()
159+
}()
160+
g.createServerWaitGroup.Wait()
161+
}()
154162
}()
155163
if limit > 0 {
156164
select {

0 commit comments

Comments
 (0)