APIServer: Cancel forked context after handler returns (#100504)

We currently cancel the context when the adapter function is done. We should wait for the entire handler we're wrapping
to finish before cancelling our context.
pull/100577/head
Mariell Hoversholm 10 months ago committed by GitHub
parent 2b2b19478a
commit 2dee9ccbbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      pkg/apiserver/endpoints/responsewriter/responsewriter.go

@ -37,11 +37,12 @@ func WrapHandler(handler http.Handler) func(req *http.Request) (*http.Response,
if err != nil {
return nil, err
}
defer cancel()
// The cancel happens in the goroutine we spawn, so as to not cancel it too early.
req = req.WithContext(ctx) // returns a shallow copy, so we can't do it as part of the adapter.
w := NewAdapter(req)
go func() {
defer cancel()
handler.ServeHTTP(w, req)
if err := w.CloseWriter(); err != nil {
klog.Errorf("error closing writer: %v", err)

Loading…
Cancel
Save