diff --git a/pkg/trace/api/evp_proxy.go b/pkg/trace/api/evp_proxy.go index 4ab15b70ab36f..452d73017aa8d 100644 --- a/pkg/trace/api/evp_proxy.go +++ b/pkg/trace/api/evp_proxy.go @@ -181,9 +181,9 @@ func (t *evpProxyTransport) RoundTrip(req *http.Request) (rresp *http.Response, timeout := getConfiguredEVPRequestTimeoutDuration(t.conf) req.Header.Set("X-Datadog-Timeout", strconv.Itoa((int(timeout.Seconds())))) deadline := time.Now().Add(timeout) - ctx, ctxCancel := context.WithDeadline(req.Context(), deadline) + //nolint:govet,lostcancel we don't need to manually cancel this context, we can rely on the parent context being cancelled + ctx, _ := context.WithDeadline(req.Context(), deadline) req = req.WithContext(ctx) - defer ctxCancel() // Set target URL and API key header (per domain) req.URL.Scheme = "https" diff --git a/pkg/trace/api/evp_proxy_test.go b/pkg/trace/api/evp_proxy_test.go index 3016b6e5ef53c..8f9afc4cb2570 100644 --- a/pkg/trace/api/evp_proxy_test.go +++ b/pkg/trace/api/evp_proxy_test.go @@ -505,4 +505,30 @@ func TestE2E(t *testing.T) { require.Equal(t, http.StatusBadGateway, resp.StatusCode, "Got: ", fmt.Sprint(resp.StatusCode)) assert.Equal(t, "http: proxy error: context deadline exceeded\n", logs) }) + + t.Run("chunked-response", func(t *testing.T) { + conf := newTestReceiverConfig() + conf.Site = "us3.datadoghq.com" + conf.Endpoints[0].APIKey = "test_api_key" + conf.EVPProxy.ReceiverTimeout = 1 // in seconds + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Transfer-Encoding", "chunked") + w.Write([]byte(`Hello`)) + w.(http.Flusher).Flush() + time.Sleep(200 * time.Millisecond) + w.Write([]byte(`World`)) // this will be discarded if the context was cancelled + })) + + req := httptest.NewRequest("POST", "/mypath/mysubpath?arg=test", bytes.NewReader(randBodyBuf)) + req.Header.Set("X-Datadog-EVP-Subdomain", "my.subdomain") + resp, logs := sendRequestThroughForwarderAgainstDummyServer(conf, req, stats, strings.TrimPrefix(server.URL, "http://")) + + resp.Body.Close() + require.Equal(t, http.StatusOK, resp.StatusCode, "Got: ", fmt.Sprint(resp.StatusCode)) + assert.Equal(t, "", logs) + body, err := io.ReadAll(resp.Body) + assert.NoError(t, err) + assert.Equal(t, "HelloWorld", string(body)) + }) }