From 1086ddf5b4cf691a6becf0b0610298ed0981b126 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Tue, 22 Oct 2024 15:02:12 +0200 Subject: [PATCH] fix: datarace --- internal/api/common/middlewares_timeout.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/api/common/middlewares_timeout.go b/internal/api/common/middlewares_timeout.go index 626c92513..f187e55ea 100644 --- a/internal/api/common/middlewares_timeout.go +++ b/internal/api/common/middlewares_timeout.go @@ -16,6 +16,13 @@ type responseWriter struct { headerWritten bool } +func (r *responseWriter) Header() http.Header { + r.Lock() + defer r.Unlock() + + return r.ResponseWriter.Header() +} + func (r *responseWriter) Write(bytes []byte) (int, error) { r.Lock() defer r.Unlock() @@ -83,7 +90,7 @@ func Timeout(configuration TimeoutConfiguration) func(h http.Handler) http.Handl }() defer close(done) - h.ServeHTTP(w, r.WithContext(newRequestContext)) + h.ServeHTTP(rw, r.WithContext(newRequestContext)) }) } }