Refactor how to handle sigterm and nginx process goroutine (#4959)

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-01-25 14:52:31 -03:00 committed by GitHub
parent 12aa72622a
commit 66ef05849f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View file

@ -125,23 +125,22 @@ func main() {
}
mc.Start()
ngx := controller.NewNGINXController(conf, mc)
go handleSigterm(ngx, func(code int) {
os.Exit(code)
})
mux := http.NewServeMux()
if conf.EnableProfiling {
go registerProfiler()
}
ngx := controller.NewNGINXController(conf, mc)
mux := http.NewServeMux()
registerHealthz(nginx.HealthPath, ngx, mux)
registerMetrics(reg, mux)
go startHTTPServer(conf.ListenPorts.Health, mux)
go ngx.Start()
ngx.Start()
handleSigterm(ngx, func(code int) {
os.Exit(code)
})
}
type exiter func(code int)

View file

@ -334,7 +334,7 @@ func (n *NGINXController) Start() {
select {
case err := <-n.ngxErrCh:
if n.isShuttingDown {
break
return
}
// if the nginx master process dies the workers continue to process requests,
@ -358,6 +358,7 @@ func (n *NGINXController) Start() {
if n.isShuttingDown {
break
}
if evt, ok := event.(store.Event); ok {
klog.V(3).Infof("Event %v received - object %v", evt.Type, evt.Obj)
if evt.Type == store.ConfigurationEvent {
@ -371,7 +372,7 @@ func (n *NGINXController) Start() {
klog.Warningf("Unexpected event type received %T", event)
}
case <-n.stopCh:
break
return
}
}
}