Merge pull request #134177 from n2h9/126379-replace-HandleCrash-with-HandleCrashWithContext-in-apiserver-00

[apiserver] [126379]: replace call to HandleCrash with call to HandleCrashWithContext in apiserver
This commit is contained in:
Kubernetes Prow Robot
2026-01-07 01:13:37 +05:30
committed by GitHub
14 changed files with 17 additions and 18 deletions

View File

@@ -174,7 +174,7 @@ func (c *RequestHeaderAuthRequestController) AllowedClientNames() []string {
// Run starts RequestHeaderAuthRequestController controller and blocks until stopCh is closed.
func (c *RequestHeaderAuthRequestController) Run(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer c.queue.ShutDown()
klog.Infof("Starting %s", c.name)

View File

@@ -1263,7 +1263,7 @@ func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.Vali
for i := 0; i < workersNumber; i++ {
go func() {
// panics don't cross goroutine boundaries
defer utilruntime.HandleCrash(func(panicReason interface{}) {
defer utilruntime.HandleCrashWithContext(ctx, func(_ context.Context, panicReason interface{}) {
errs <- fmt.Errorf("DeleteCollection goroutine panicked: %v", panicReason)
})
defer wg.Done()
@@ -1288,7 +1288,7 @@ func (e *Store) DeleteCollection(ctx context.Context, deleteValidation rest.Vali
}
// In case of all workers exit, notify distributor.
go func() {
defer utilruntime.HandleCrash(func(panicReason interface{}) {
defer utilruntime.HandleCrashWithContext(ctx, func(_ context.Context, panicReason interface{}) {
errs <- fmt.Errorf("DeleteCollection workers closer panicked: %v", panicReason)
})
wg.Wait()

View File

@@ -199,7 +199,7 @@ func (c *ConfigMapCAController) RunOnce(ctx context.Context) error {
// Run starts the kube-apiserver and blocks until stopCh is closed.
func (c *ConfigMapCAController) Run(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer c.queue.ShutDown()
klog.InfoS("Starting controller", "name", c.name)

View File

@@ -155,7 +155,7 @@ func (c *DynamicFileCAContent) RunOnce(ctx context.Context) error {
// Run starts the controller and blocks until stopCh is closed.
func (c *DynamicFileCAContent) Run(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer c.queue.ShutDown()
klog.InfoS("Starting controller", "name", c.name)

View File

@@ -129,7 +129,7 @@ func (c *DynamicCertKeyPairContent) RunOnce(ctx context.Context) error {
// Run starts the controller and blocks until context is killed.
func (c *DynamicCertKeyPairContent) Run(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer c.queue.ShutDown()
klog.InfoS("Starting controller", "name", c.name)

View File

@@ -533,7 +533,7 @@ func (s preparedGenericAPIServer) RunWithContext(ctx context.Context) error {
// If UDS profiling is enabled, start a local http server listening on that socket
if s.UnprotectedDebugSocket != nil {
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
klog.Error(s.UnprotectedDebugSocket.RunWithContext(ctx))
}()
}

View File

@@ -195,8 +195,7 @@ func (s *GenericAPIServer) isPostStartHookRegistered(name string) bool {
func runPostStartHook(name string, entry postStartHookEntry, context PostStartHookContext) {
var err error
func() {
// don't let the hook *accidentally* panic and kill the server
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(context)
err = entry.hook(context)
}()
// if the hook intentionally wants to kill server, let it.

View File

@@ -92,7 +92,7 @@ func NewDynamicEncryptionConfiguration(
// Run starts the controller and blocks until ctx is canceled.
func (d *DynamicEncryptionConfigContent) Run(ctx context.Context) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
klog.InfoS("Starting controller", "name", d.name)
defer klog.InfoS("Shutting down controller", "name", d.name)
@@ -101,7 +101,7 @@ func (d *DynamicEncryptionConfigContent) Run(ctx context.Context) {
wg.Add(1)
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer wg.Done()
defer d.queue.ShutDown()
<-ctx.Done()
@@ -109,7 +109,7 @@ func (d *DynamicEncryptionConfigContent) Run(ctx context.Context) {
wg.Add(1)
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer wg.Done()
d.runWorker(ctx)
}()

View File

@@ -434,7 +434,7 @@ func (c *cacheWatcher) sendWatchCacheEvent(event *watchCacheEvent) {
}
func (c *cacheWatcher) processInterval(ctx context.Context, cacheInterval *watchCacheInterval, resourceVersion uint64) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer close(c.result)
defer c.Stop()

View File

@@ -71,7 +71,7 @@ func (pr *ConditionalProgressRequester) Run(stopCh <-chan struct{}) {
ctx = metadata.NewOutgoingContext(ctx, pr.contextMetadata)
}
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
<-stopCh
pr.mux.Lock()
defer pr.mux.Unlock()

View File

@@ -109,7 +109,7 @@ func (f *defaultFeatureSupportChecker) checkClient(ctx context.Context, c client
}
f.checkingEndpoint[ep] = struct{}{}
go func(ep string) {
defer runtime.HandleCrash()
defer runtime.HandleCrashWithContext(ctx)
err := delayFunc.Until(ctx, true, true, func(ctx context.Context) (done bool, err error) {
internalErr := f.clientSupportsRequestWatchProgress(ctx, c, ep)
return internalErr == nil, nil

View File

@@ -86,7 +86,7 @@ func NewGRPCService(ctx context.Context, endpoint string, callTimeout time.Durat
s.kmsClient = kmsapi.NewKeyManagementServiceClient(s.connection)
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
<-ctx.Done()
_ = s.connection.Close()

View File

@@ -83,7 +83,7 @@ func NewGRPCService(ctx context.Context, endpoint, providerName string, callTime
s.kmsClient = kmsapi.NewKeyManagementServiceClient(s.connection)
go func() {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
<-ctx.Done()
_ = s.connection.Close()

View File

@@ -51,7 +51,7 @@ const (
)
func (h *peerProxyHandler) RunPeerDiscoveryCacheSync(ctx context.Context, workers int) {
defer utilruntime.HandleCrash()
defer utilruntime.HandleCrashWithContext(ctx)
defer h.peerLeaseQueue.ShutDown()
defer func() {
err := h.apiserverIdentityInformer.Informer().RemoveEventHandler(h.leaseRegistration)