fix(metrics): add timeouts to metrics HTTP server (#7469)

Add ReadTimeout, WriteTimeout, and IdleTimeout (5s each) to metrics HTTP
server and test to verify timeout behavior prevents hanging connections.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
Ville Vesilehto
2025-08-29 06:03:55 +03:00
committed by GitHub
parent c38c2ca66f
commit 5a6700c39c
2 changed files with 53 additions and 1 deletions

View File

@@ -98,7 +98,12 @@ func (m *Metrics) OnStartup() error {
m.mux.Handle("/metrics", promhttp.HandlerFor(m.Reg, promhttp.HandlerOpts{}))
// creating some helper variables to avoid data races on m.srv and m.ln
server := &http.Server{Handler: m.mux}
server := &http.Server{
Handler: m.mux,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 5 * time.Second,
}
m.srv = server
go func() {