From 0498acc2631adc034b5c725ce644f19ad7ad9941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandor=20Sz=C3=BCcs?= Date: Mon, 1 Jul 2024 15:52:29 +0200 Subject: [PATCH] fix: goroutine leak for flightrecorder send data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sandor Szücs --- proxy/flightrecorder_test.go | 5 +++++ proxy/proxy.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/proxy/flightrecorder_test.go b/proxy/flightrecorder_test.go index cc4821bea0..dcf57d56df 100644 --- a/proxy/flightrecorder_test.go +++ b/proxy/flightrecorder_test.go @@ -62,6 +62,11 @@ func TestFlightRecorder(t *testing.T) { if err != nil { t.Fatalf("Failed to GET %q: %v", pr.URL, err) } + defer rsp.Body.Close() + _, err = io.ReadAll(rsp.Body) + if err != nil { + t.Fatalf("Failed to read body: %v", err) + } switch rsp.StatusCode { case 200, 201, 204: diff --git a/proxy/proxy.go b/proxy/proxy.go index fe5995b548..89391289e1 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -935,9 +935,11 @@ func (p *Proxy) writeTraceIfTooSlow(ctx *context) { p.log.Errorf("Failed to create request to %q to send a trace: %v", p.flightRecorderURL.String(), err) } - rsp, err := http.DefaultClient.Do(req) + rsp, err := p.roundTripper.RoundTrip(req) if err != nil { p.log.Errorf("Failed to write trace to %q: %v", p.flightRecorderURL.String(), err) + } else { + rsp.Body.Close() } switch rsp.StatusCode { case 200, 201, 204: