k3s/pkg/util/context.go
Brad Davidson 4974fc7c24 Use sync.WaitGroup to avoid exiting before components have shut down
Currently only waits on etcd and kine, as other components
are stateless and do not need to shut down cleanly.

Terminal but non-fatal errors now request shutdown via context
cancellation, instead of just logging a fatal error.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2025-09-17 09:37:08 -07:00

20 lines
423 B
Go

package util
import (
"context"
"time"
)
const DefaultContextDelay = 5 * time.Second
// DelayCancel returns a context that will be cancelled
// with a delay after the parent context has been cancelled.
func DelayCancel(ctx context.Context, delay time.Duration) context.Context {
dctx, dcancel := context.WithCancel(context.Background())
go func() {
<-ctx.Done()
time.Sleep(delay)
dcancel()
}()
return dctx
}