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

@@ -4,6 +4,7 @@ import (
"context"
"net/http"
"strconv"
"time"
"github.com/actions/actions-runner-controller/github/actions"
"github.com/go-logr/logr"
@@ -338,7 +339,9 @@ func (e *exporter) ListenAndServe(ctx context.Context) error {
e.logger.Info("starting metrics server", "addr", e.srv.Addr)
go func() {
<-ctx.Done()
e.logger.Info("stopping metrics server")
e.logger.Info("stopping metrics server", "err", ctx.Err())
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
e.srv.Shutdown(ctx)
}()
return e.srv.ListenAndServe()