diff --git a/proxy/round_tripper/proxy_round_tripper.go b/proxy/round_tripper/proxy_round_tripper.go index 470f1e2e..49819b27 100644 --- a/proxy/round_tripper/proxy_round_tripper.go +++ b/proxy/round_tripper/proxy_round_tripper.go @@ -248,10 +248,12 @@ func (rt *roundTripper) RoundTrip(originalRequest *http.Request) (*http.Response } // if the client disconnects before response is sent then return context.Canceled (499) instead of the gateway error - if err != nil && originalRequest.Context().Err() == context.Canceled && err != context.Canceled { + if err != nil && errors.Is(originalRequest.Context().Err(), context.Canceled) && !errors.Is(err, context.Canceled) { rt.logger.Error("gateway-error-and-original-request-context-cancelled", zap.Error(err)) err = originalRequest.Context().Err() - originalRequest.Body.Close() + if originalRequest.Body != nil { + _ = originalRequest.Body.Close() + } } // If we have an error from the round trip, we prefer it over errors