Shutdown metrics server when listener exits (#3445)

This commit is contained in:
Nikola Jokic
2024-04-16 21:29:03 +02:00
committed by GitHub
parent 4ee49fee14
commit f965dfef73
4 changed files with 14 additions and 7 deletions

View File

@@ -117,15 +117,19 @@ func (app *App) Run(ctx context.Context) error {
}
g, ctx := errgroup.WithContext(ctx)
metricsCtx, cancelMetrics := context.WithCancelCause(ctx)
g.Go(func() error {
app.logger.Info("Starting listener")
return app.listener.Listen(ctx, app.worker)
listnerErr := app.listener.Listen(ctx, app.worker)
cancelMetrics(fmt.Errorf("Listener exited: %w", listnerErr))
return listnerErr
})
if app.metrics != nil {
g.Go(func() error {
app.logger.Info("Starting metrics server")
return app.metrics.ListenAndServe(ctx)
return app.metrics.ListenAndServe(metricsCtx)
})
}