From 01c73819c0525e18242deba8770264b2c59c275b Mon Sep 17 00:00:00 2001 From: Pablu Date: Mon, 8 Jun 2026 22:43:30 +0200 Subject: [PATCH] fix metrics not stopping correctly, deadlocking the whole shutdown process --- middleware/metrics.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/middleware/metrics.go b/middleware/metrics.go index ed61883..b53148e 100644 --- a/middleware/metrics.go +++ b/middleware/metrics.go @@ -136,17 +136,12 @@ func (m *Metrics) Flush() { func (m *Metrics) Stop(ctx context.Context) { log.Info().Msg("Stopping Request Metrics") + m.stop <- struct{}{} + // Drain remaining metrics for len(m.c) > 0 { - select { - case rm := <-m.c: - m.calculateDuration(rm) - case <-ctx.Done(): - m.stop <- struct{}{} - log.Warn().Msg("Hard Stopped Request Metrics") - return - } + rm := <-m.c + m.calculateDuration(rm) } m.Flush() - m.stop <- struct{}{} log.Info().Msg("Stopped Request Metrics") }