mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-03 21:08:25 +00:00 
			
		
		
		
	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.
This commit is contained in:
		@@ -59,7 +59,15 @@ func (g *Manager) start() {
 | 
				
			|||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		defer close(startupDone)
 | 
							defer close(startupDone)
 | 
				
			||||||
		// Wait till we're done getting all the listeners and then close the unused ones
 | 
							// Wait till we're done getting all 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
 | 
							// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
 | 
				
			||||||
		_ = CloseProvidedListeners()
 | 
							_ = CloseProvidedListeners()
 | 
				
			||||||
		g.notify(readyMsg)
 | 
							g.notify(readyMsg)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -150,7 +150,15 @@ func (g *Manager) awaitServer(limit time.Duration) bool {
 | 
				
			|||||||
	c := make(chan struct{})
 | 
						c := make(chan struct{})
 | 
				
			||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		defer close(c)
 | 
							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 {
 | 
						if limit > 0 {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user