Skip to content

Commit e599018

Browse files
authored
Merge pull request #1747 from ricardomaraschini/fix-context-cancellation
chore: give tracing.Shutdown() its own context
2 parents 483c9c1 + f9a3be8 commit e599018

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cmd/descheduler/app/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os/signal"
2424
"syscall"
25+
"time"
2526

2627
"github.com/spf13/cobra"
2728

@@ -111,7 +112,14 @@ func Run(rootCtx context.Context, rs *options.DeschedulerServer) error {
111112
if err != nil {
112113
klog.ErrorS(err, "failed to create tracer provider")
113114
}
114-
defer tracing.Shutdown(ctx)
115+
defer func() {
116+
// we give the tracing.Shutdown() its own context as the
117+
// original context may have been cancelled already. we
118+
// have arbitrarily chosen the timeout duration.
119+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
120+
defer cancel()
121+
tracing.Shutdown(ctx)
122+
}()
115123

116124
// increase the fake watch channel so the dry-run mode can be run
117125
// over a cluster with thousands of pods

0 commit comments

Comments
 (0)