1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-25 20:59:28 +01:00

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.
This commit is contained in:
Ricardo Maraschini
2025-09-24 12:26:05 +02:00
parent 483c9c1499
commit f9a3be8cde

View File

@@ -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