apiserver: all bookkeeping must complete before apf handler returns

all bookkeeping must complete before the apf handler returns,
whether it panics or returns normally
This commit is contained in:
Abu Kashem 2024-09-05 12:01:36 -04:00
parent 0c8632de57
commit 71d9307eae
No known key found for this signature in database
GPG Key ID: E5ECC1124B5F9C68

View File

@ -266,17 +266,23 @@ 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:
// Protect from the situation when request will not reach storage layer defer func() {
// and the initialization signal will not be send. // Protect from the situation when request will not reach storage layer
// It has to happen before waiting on the resultCh below. // and the initialization signal will not be send.
watchInitializationSignal.Signal() // It has to happen before waiting on the resultCh below.
// TODO: Consider finishing the request as soon as Handle call panics. watchInitializationSignal.Signal()
if err := <-resultCh; err != nil { // TODO: Consider finishing the request as soon as Handle call panics.
panic(err) if err := <-resultCh; err != nil {
} 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)