Avoid panic during stop
This commit is contained in:
parent
a80cca95a2
commit
f3aefe282c
1 changed files with 26 additions and 20 deletions
|
@ -137,29 +137,35 @@ type serverEntryPoint struct {
|
||||||
|
|
||||||
func (s serverEntryPoint) Shutdown(ctx context.Context) {
|
func (s serverEntryPoint) Shutdown(ctx context.Context) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
if s.httpServer != nil {
|
||||||
go func() {
|
wg.Add(1)
|
||||||
defer wg.Done()
|
go func() {
|
||||||
if err := s.httpServer.Shutdown(ctx); err != nil {
|
defer wg.Done()
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if err := s.httpServer.Shutdown(ctx); err != nil {
|
||||||
log.Debugf("Wait server shutdown is over due to: %s", err)
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
err = s.httpServer.Close()
|
log.Debugf("Wait server shutdown is over due to: %s", err)
|
||||||
if err != nil {
|
err = s.httpServer.Close()
|
||||||
log.Error(err)
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}()
|
}
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
if s.hijackConnectionTracker != nil {
|
||||||
defer wg.Done()
|
wg.Add(1)
|
||||||
if err := s.hijackConnectionTracker.Shutdown(ctx); err != nil {
|
go func() {
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
defer wg.Done()
|
||||||
log.Debugf("Wait hijack connection is over due to: %s", err)
|
if err := s.hijackConnectionTracker.Shutdown(ctx); err != nil {
|
||||||
s.hijackConnectionTracker.Close()
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
|
log.Debugf("Wait hijack connection is over due to: %s", err)
|
||||||
|
s.hijackConnectionTracker.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
}()
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue