mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
Merge pull request #127029 from tkashem/apf-fix-watch-panic-handling
apf: request handler must wait for watch init goroutine to return
This commit is contained in:
commit
8bc073a5fe
@ -266,9 +266,10 @@ func (h *priorityAndFairnessHandler) Handle(w http.ResponseWriter, r *http.Reque
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-shouldStartWatchCh:
|
case <-shouldStartWatchCh:
|
||||||
watchCtx := utilflowcontrol.WithInitializationSignal(ctx, watchInitializationSignal)
|
func() {
|
||||||
watchReq = r.WithContext(watchCtx)
|
// TODO: if both goroutines panic, propagate the stack traces from both
|
||||||
h.handler.ServeHTTP(w, watchReq)
|
// goroutines so they are logged properly:
|
||||||
|
defer func() {
|
||||||
// Protect from the situation when request will not reach storage layer
|
// Protect from the situation when request will not reach storage layer
|
||||||
// and the initialization signal will not be send.
|
// and the initialization signal will not be send.
|
||||||
// It has to happen before waiting on the resultCh below.
|
// It has to happen before waiting on the resultCh below.
|
||||||
@ -277,6 +278,11 @@ func (h *priorityAndFairnessHandler) Handle(w http.ResponseWriter, r *http.Reque
|
|||||||
if err := <-resultCh; err != nil {
|
if err := <-resultCh; err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
watchCtx := utilflowcontrol.WithInitializationSignal(ctx, watchInitializationSignal)
|
||||||
|
watchReq = r.WithContext(watchCtx)
|
||||||
|
h.handler.ServeHTTP(w, watchReq)
|
||||||
|
}()
|
||||||
case err := <-resultCh:
|
case err := <-resultCh:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -177,11 +177,21 @@ func newApfHandlerWithFilter(t *testing.T, flowControlFilter utilflowcontrol.Int
|
|||||||
r = r.WithContext(apirequest.WithUser(r.Context(), &user.DefaultInfo{
|
r = r.WithContext(apirequest.WithUser(r.Context(), &user.DefaultInfo{
|
||||||
Groups: []string{user.AllUnauthenticated},
|
Groups: []string{user.AllUnauthenticated},
|
||||||
}))
|
}))
|
||||||
apfHandler.ServeHTTP(w, r)
|
func() {
|
||||||
postExecute()
|
// the APF handler completes its run, either normally or
|
||||||
|
// with a panic, in either case, all APF book keeping must
|
||||||
|
// be completed by now. Also, whether the request is
|
||||||
|
// executed or rejected, we expect the counter to be zero.
|
||||||
|
// TODO: all test(s) using this filter must run
|
||||||
|
// serially to each other
|
||||||
|
defer func() {
|
||||||
if atomicReadOnlyExecuting != 0 {
|
if atomicReadOnlyExecuting != 0 {
|
||||||
t.Errorf("Wanted %d requests executing, got %d", 0, atomicReadOnlyExecuting)
|
t.Errorf("Wanted %d requests executing, got %d", 0, atomicReadOnlyExecuting)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
apfHandler.ServeHTTP(w, r)
|
||||||
|
postExecute()
|
||||||
|
}()
|
||||||
}), requestInfoFactory)
|
}), requestInfoFactory)
|
||||||
|
|
||||||
return handler
|
return handler
|
||||||
|
Loading…
Reference in New Issue
Block a user