mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Merge pull request #93646 from gobomb/fix-panic-defer
let panics propagate up when processLoop in informer controller panic in client-go
This commit is contained in:
commit
5a7970a42b
@ -144,11 +144,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
|
||||
|
@ -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!")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user