From 1a850b48008b42d36122001cdd8ef129859f5e73 Mon Sep 17 00:00:00 2001 From: clarabennett2626 Date: Tue, 17 Feb 2026 11:05:02 -0500 Subject: [PATCH] fix: read HTTP response body before context cancellation Fixes #3141 In executeRequest, the request context is canceled via defer cancel() when the function returns. However, the response body is read later in processResponse, which causes 'context canceled' errors for large or slow responses. The fix reads the entire response body before executeRequest returns (while the context is still active) and replaces resp.Body with a buffered reader so processResponse can consume it normally. --- pkg/components/http/http.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/components/http/http.go b/pkg/components/http/http.go index a58ef4c50e..b4eed9326d 100644 --- a/pkg/components/http/http.go +++ b/pkg/components/http/http.go @@ -628,6 +628,18 @@ func (e *HTTP) executeRequest(httpCtx core.HTTPContext, spec Spec, timeout time. return nil, err } + // Read the entire response body before returning, because the deferred + // cancel() will cancel the request context and abort any in-flight reads. + // We replace resp.Body with the buffered content so callers (processResponse) + // can read it without hitting "context canceled" errors. + // See: https://github.com/superplanehq/superplane/issues/3141 + bodyBytes, err := io.ReadAll(resp.Body) + resp.Body.Close() + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } + resp.Body = io.NopCloser(bytes.NewReader(bodyBytes)) + return resp, nil }