mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 21:32:03 +08:00
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.
This commit is contained in:

committed by
GitHub

parent
2b2b19478a
commit
2dee9ccbbc
@ -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)
|
||||
|
Reference in New Issue
Block a user