From f9a3be8cde9852c8d10887f9e21bd2297d64d7f1 Mon Sep 17 00:00:00 2001 From: Ricardo Maraschini Date: Wed, 24 Sep 2025 12:26:05 +0200 Subject: [PATCH] chore: give tracing.Shutdown() its own context the tracing.Shutdown() uses the context so we must guarantee that the context we use is valid regardless if the original context being cancelled already. this change introduces an exclusive context for the shutdown process with an arbitrary timeout. --- cmd/descheduler/app/server.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/descheduler/app/server.go b/cmd/descheduler/app/server.go index 7ecaf04e2..29a0cdad0 100644 --- a/cmd/descheduler/app/server.go +++ b/cmd/descheduler/app/server.go @@ -22,6 +22,7 @@ import ( "io" "os/signal" "syscall" + "time" "github.com/spf13/cobra" @@ -111,7 +112,14 @@ func Run(rootCtx context.Context, rs *options.DeschedulerServer) error { if err != nil { klog.ErrorS(err, "failed to create tracer provider") } - defer tracing.Shutdown(ctx) + defer func() { + // we give the tracing.Shutdown() its own context as the + // original context may have been cancelled already. we + // have arbitrarily chosen the timeout duration. + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + tracing.Shutdown(ctx) + }() // increase the fake watch channel so the dry-run mode can be run // over a cluster with thousands of pods