feat: use contextual HandleCrash when possible

This commit is contained in:
Maxime
2026-01-06 15:53:22 +00:00
parent 03e14cc943
commit a168b6b05d
5 changed files with 6 additions and 6 deletions

View File

@@ -767,7 +767,7 @@ func (m *kubeGenericRuntimeManager) executePreStopHook(ctx context.Context, pod
done := make(chan struct{})
go func() {
defer close(done)
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
if _, err := m.runner.Run(ctx, containerID, pod, containerSpec, containerSpec.Lifecycle.PreStop); err != nil {
logger.Error(err, "PreStop hook failed", "pod", klog.KObj(pod), "podUID", pod.UID,
"containerName", containerSpec.Name, "containerID", containerID.String())
@@ -923,7 +923,7 @@ func (m *kubeGenericRuntimeManager) killContainersWithSyncResult(ctx context.Con
}
for _, container := range runningPod.Containers {
go func(container *kubecontainer.Container) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer wg.Done()
killContainerResult := kubecontainer.NewSyncResult(kubecontainer.KillContainer, container.Name)

View File

@@ -78,7 +78,7 @@ func (ow *realWatcher) Start(ctx context.Context, ref *v1.ObjectReference) error
go func() {
logger := klog.FromContext(ctx)
defer runtime.HandleCrash()
defer runtime.HandleCrashWithContext(ctx)
for event := range outStream {
if event.VictimContainerName == recordEventContainerName {

View File

@@ -107,7 +107,7 @@ type pluginManager struct {
var _ PluginManager = &pluginManager{}
func (pm *pluginManager) Run(ctx context.Context, sourcesReady config.SourcesReady, stopCh <-chan struct{}) {
defer runtime.HandleCrash()
defer runtime.HandleCrashWithContext(ctx)
logger := klog.FromContext(ctx)

View File

@@ -214,7 +214,7 @@ func (w *worker) stop() {
// Returns whether the worker should continue.
func (w *worker) doProbe(ctx context.Context) (keepGoing bool) {
defer func() { recover() }() // Actually eat panics (HandleCrash takes care of logging)
defer runtime.HandleCrash(func(_ interface{}) { keepGoing = true })
defer runtime.HandleCrashWithContext(ctx, func(ctx context.Context, _ interface{}) { keepGoing = true })
logger := klog.FromContext(ctx)
startTime := time.Now()

View File

@@ -298,7 +298,7 @@ func (e *VolumeAttachLimitExceededError) Error() string {
func (vm *volumeManager) Run(ctx context.Context, sourcesReady config.SourcesReady) {
logger := klog.FromContext(ctx)
defer runtime.HandleCrash()
defer runtime.HandleCrashWithContext(ctx)
if vm.kubeClient != nil {
// start informer for CSIDriver