Skip to content

Commit 6db096d

Browse files
morlayaauren
authored andcommitted
fix: avoid to use http.DefaultServeMux which includes default routes inited by go like /debug/pprof
1 parent 16ff02d commit 6db096d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pkg/healthcheck/health_controller.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,17 @@ func (hc *HealthController) CheckHealth() bool {
220220
// RunServer starts the HealthController's server
221221
func (hc *HealthController) RunServer(stopCh <-chan struct{}, wg *sync.WaitGroup) {
222222
defer wg.Done()
223+
224+
mux := http.NewServeMux()
225+
223226
srv := &http.Server{
224227
Addr: ":" + strconv.Itoa(int(hc.HealthPort)),
225-
Handler: http.DefaultServeMux,
226-
ReadHeaderTimeout: 5 * time.Second}
227-
http.HandleFunc("/healthz", hc.Handler)
228+
Handler: mux,
229+
ReadHeaderTimeout: 5 * time.Second,
230+
}
231+
232+
mux.HandleFunc("/healthz", hc.Handler)
233+
228234
if hc.Config.HealthPort > 0 {
229235
hc.HTTPEnabled = true
230236
go func() {

pkg/metrics/metrics_controller.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,15 @@ func (mc *Controller) Run(healthChan chan<- *healthcheck.ControllerHeartbeat, st
260260
DefaultRegisterer.MustRegister(BuildInfo)
261261
DefaultRegisterer.MustRegister(ControllerIpvsMetricsExportTime)
262262

263+
mux := http.NewServeMux()
264+
263265
srv := &http.Server{
264266
Addr: mc.MetricsAddr + ":" + strconv.Itoa(int(mc.MetricsPort)),
265-
Handler: http.DefaultServeMux,
267+
Handler: mux,
266268
ReadHeaderTimeout: 5 * time.Second}
267269

268270
// add prometheus handler on metrics path
269-
http.Handle(mc.MetricsPath, Handler())
271+
mux.Handle(mc.MetricsPath, Handler())
270272

271273
go func() {
272274
if err := srv.ListenAndServe(); err != nil {

0 commit comments

Comments
 (0)