mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-11-06 05:17:08 +00:00
protecting a couple go funcs with handle crash
This commit is contained in:
1 parent
512785fb4c
commit
4fce9a9d84
2 files changed
+11
-1
No files matched your search
@@ -19,6 +19,8 @@ package app
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
)
|
||||
|
||||
// This file contains utility functions for implementing controller wrappers,
|
||||
@@ -33,6 +35,7 @@ func (rx runFuncSlice) Run(ctx context.Context) {
|
||||
wg.Add(len(rx))
|
||||
for _, fnc := range rx {
|
||||
go func() {
|
||||
defer utilruntime.HandleCrashWithContext(ctx)
|
||||
defer wg.Done()
|
||||
fnc(ctx)
|
||||
}()
|
||||
|
||||
@@ -377,7 +377,10 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
|
||||
}
|
||||
healthzHandler.AddHealthChecker(healthz.NewInformerSyncHealthz(waitForSync))
|
||||
|
||||
go leaseCandidate.Run(ctx)
|
||||
go func() {
|
||||
defer utilruntime.HandleCrashWithContext(ctx)
|
||||
leaseCandidate.Run(ctx)
|
||||
}()
|
||||
}
|
||||
|
||||
// Start the main lock.
|
||||
@@ -774,6 +777,8 @@ func RunControllers(ctx context.Context, controllerCtx ControllerContext, contro
|
||||
loggingCtx, cancelLoggingCtx := context.WithCancel(context.Background())
|
||||
defer cancelLoggingCtx()
|
||||
go func() {
|
||||
defer utilruntime.HandleCrashWithContext(ctx)
|
||||
|
||||
// Only start logging when terminating.
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -805,11 +810,13 @@ func RunControllers(ctx context.Context, controllerCtx ControllerContext, contro
|
||||
|
||||
terminatedCh := make(chan struct{})
|
||||
go func() {
|
||||
defer utilruntime.HandleCrashWithContext(ctx)
|
||||
defer close(terminatedCh)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(len(controllers))
|
||||
for _, controller := range controllers {
|
||||
go func() {
|
||||
defer utilruntime.HandleCrashWithContext(ctx)
|
||||
defer wg.Done()
|
||||
|
||||
// It would be better to unblock and return on context cancelled here,
|
||||
|
||||
Reference in new issue
Block a user