From 434d22145d384db7aa90f4cd206fc8a4d112e5bc Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Mon, 30 Jun 2025 12:58:52 -0400 Subject: [PATCH] When shutting down the OTel providers have a ten second timeout. (#3199) I noticed a misconfigured metrics URL would prevent the process from quiting because it was trying to flush metrics forever. --- injection/sharedmain/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/injection/sharedmain/main.go b/injection/sharedmain/main.go index ae085d071..ccb9161ec 100644 --- a/injection/sharedmain/main.go +++ b/injection/sharedmain/main.go @@ -278,12 +278,13 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto mp, tp := SetupObservabilityOrDie(ctx, component, logger, pprof) defer func() { - if err := mp.Shutdown(context.Background()); err != nil { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + if err := mp.Shutdown(ctx); err != nil { logger.Errorw("Error flushing metrics", zap.Error(err)) } - }() - defer func() { - if err := tp.Shutdown(context.Background()); err != nil { + if err := tp.Shutdown(ctx); err != nil { logger.Errorw("Error flushing traces", zap.Error(err)) } }()