Skip to content

Commit

Permalink
Merge pull request #94425 from gobomb/automated-cherry-pick-of-#93646…
Browse files Browse the repository at this point in the history
…-origin-release-1.17

Automated cherry pick of #93646: let panics propagate up when processLoop panic

Kubernetes-commit: 15e4b3facc3d40f3f641cf171bf620befa63360d
  • Loading branch information
k8s-publishing-bot committed Sep 4, 2020
2 parents 59ba4f9 + 9729991 commit 92dd56d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/cache/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func (c *controller) Run(stopCh <-chan struct{}) {
c.reflectorMutex.Unlock()

var wg wait.Group
defer wg.Wait()

wg.StartWithChannel(stopCh, r.Run)

wait.Until(c.processLoop, time.Second, stopCh)
wg.Wait()
}

// Returns true once this controller has completed an initial resource listing
Expand Down
46 changes: 46 additions & 0 deletions tools/cache/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,49 @@ func TestUpdate(t *testing.T) {
testDoneWG.Wait()
close(stop)
}

func TestPanicPropagated(t *testing.T) {
// source simulates an apiserver object endpoint.
source := fcache.NewFakeControllerSource()

// Make a controller that just panic if the AddFunc is called.
_, controller := NewInformer(
source,
&v1.Pod{},
time.Millisecond*100,
ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
// Create a panic.
panic("Just panic.")
},
},
)

// Run the controller and run it until we close stop.
stop := make(chan struct{})
defer close(stop)

propagated := make(chan interface{})
go func() {
defer func() {
if r := recover(); r != nil {
propagated <- r
}
}()
controller.Run(stop)
}()
// Let's add a object to the source. It will trigger a panic.
source.Add(&v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "test"}})

// Check if the panic propagated up.
select {
case p := <-propagated:
if p == "Just panic." {
t.Logf("Test Passed")
} else {
t.Errorf("unrecognized panic in controller run: %v", p)
}
case <-time.After(wait.ForeverTestTimeout):
t.Errorf("timeout: the panic failed to propagate from the controller run method!")
}
}

0 comments on commit 92dd56d

Please sign in to comment.