mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Merge pull request #87338 from deads2k/catchpanics
add crash protection to wait functions that were missing it
This commit is contained in:
		@@ -203,6 +203,12 @@ var ErrWaitTimeout = errors.New("timed out waiting for the condition")
 | 
				
			|||||||
// if the loop should be aborted.
 | 
					// if the loop should be aborted.
 | 
				
			||||||
type ConditionFunc func() (done bool, err error)
 | 
					type ConditionFunc func() (done bool, err error)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// runConditionWithCrashProtection runs a ConditionFunc with crash protection
 | 
				
			||||||
 | 
					func runConditionWithCrashProtection(condition ConditionFunc) (bool, error) {
 | 
				
			||||||
 | 
						defer runtime.HandleCrash()
 | 
				
			||||||
 | 
						return condition()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Backoff holds parameters applied to a Backoff function.
 | 
					// Backoff holds parameters applied to a Backoff function.
 | 
				
			||||||
type Backoff struct {
 | 
					type Backoff struct {
 | 
				
			||||||
	// The initial duration.
 | 
						// The initial duration.
 | 
				
			||||||
@@ -289,7 +295,7 @@ func contextForChannel(parentCh <-chan struct{}) (context.Context, context.Cance
 | 
				
			|||||||
// In all other cases, ErrWaitTimeout is returned.
 | 
					// In all other cases, ErrWaitTimeout is returned.
 | 
				
			||||||
func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error {
 | 
					func ExponentialBackoff(backoff Backoff, condition ConditionFunc) error {
 | 
				
			||||||
	for backoff.Steps > 0 {
 | 
						for backoff.Steps > 0 {
 | 
				
			||||||
		if ok, err := condition(); err != nil || ok {
 | 
							if ok, err := runConditionWithCrashProtection(condition); err != nil || ok {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if backoff.Steps == 1 {
 | 
							if backoff.Steps == 1 {
 | 
				
			||||||
@@ -335,7 +341,7 @@ func PollImmediate(interval, timeout time.Duration, condition ConditionFunc) err
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func pollImmediateInternal(wait WaitFunc, condition ConditionFunc) error {
 | 
					func pollImmediateInternal(wait WaitFunc, condition ConditionFunc) error {
 | 
				
			||||||
	done, err := condition()
 | 
						done, err := runConditionWithCrashProtection(condition)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -364,7 +370,7 @@ func PollInfinite(interval time.Duration, condition ConditionFunc) error {
 | 
				
			|||||||
// Some intervals may be missed if the condition takes too long or the time
 | 
					// Some intervals may be missed if the condition takes too long or the time
 | 
				
			||||||
// window is too short.
 | 
					// window is too short.
 | 
				
			||||||
func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error {
 | 
					func PollImmediateInfinite(interval time.Duration, condition ConditionFunc) error {
 | 
				
			||||||
	done, err := condition()
 | 
						done, err := runConditionWithCrashProtection(condition)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -431,7 +437,7 @@ func WaitFor(wait WaitFunc, fn ConditionFunc, done <-chan struct{}) error {
 | 
				
			|||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case _, open := <-c:
 | 
							case _, open := <-c:
 | 
				
			||||||
			ok, err := fn()
 | 
								ok, err := runConditionWithCrashProtection(fn)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user