Skip to content

Commit

Permalink
Fix graceful shutdown if admin server is not enabled (#4155)
Browse files Browse the repository at this point in the history
Co-authored-by: oleksandr <[email protected]>
  • Loading branch information
linux019 and oleksandr authored Feb 11, 2025
1 parent ca0118c commit d4e27cb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
stopAdmin := make(chan os.Signal)
stopMain := make(chan os.Signal)
stopPrometheus := make(chan os.Signal)
stopChannels := []chan<- os.Signal{stopMain}
done := make(chan struct{})

if cfg.UnixSocketEnable && len(cfg.UnixSocketName) > 0 { // start the unix_socket server if config enable-it.
Expand Down Expand Up @@ -54,6 +55,7 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
}

if cfg.Admin.Enabled {
stopChannels = append(stopChannels, stopAdmin)
adminServer := newAdminServer(cfg, adminHandler)
go shutdownAfterSignals(adminServer, stopAdmin, done)

Expand All @@ -70,18 +72,18 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
prometheusListener net.Listener
prometheusServer = newPrometheusServer(cfg, metrics)
)
stopChannels = append(stopChannels, stopPrometheus)
go shutdownAfterSignals(prometheusServer, stopPrometheus, done)
if prometheusListener, err = newTCPListener(prometheusServer.Addr, nil); err != nil {
glog.Errorf("Error listening for TCP connections on %s: %v for prometheus server", prometheusServer.Addr, err)
return
}

go runServer(prometheusServer, "Prometheus", prometheusListener)
wait(stopSignals, done, stopMain, stopAdmin, stopPrometheus)
} else {
wait(stopSignals, done, stopMain, stopAdmin)
}

wait(stopSignals, done, stopChannels...)

return
}

Expand Down

0 comments on commit d4e27cb

Please sign in to comment.