mirror of https://github.com/grafana/grafana.git
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:
parent
2b2b19478a
commit
2dee9ccbbc
|
|
@ -37,11 +37,12 @@ func WrapHandler(handler http.Handler) func(req *http.Request) (*http.Response,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
req = req.WithContext(ctx) // returns a shallow copy, so we can't do it as part of the adapter.
|
||||||
|
|
||||||
w := NewAdapter(req)
|
w := NewAdapter(req)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer cancel()
|
||||||
handler.ServeHTTP(w, req)
|
handler.ServeHTTP(w, req)
|
||||||
if err := w.CloseWriter(); err != nil {
|
if err := w.CloseWriter(); err != nil {
|
||||||
klog.Errorf("error closing writer: %v", err)
|
klog.Errorf("error closing writer: %v", err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue