From d96f2e50f4bc4318917dcf86a9fb6ab1e85ae877 Mon Sep 17 00:00:00 2001 From: Maximilian Moehl Date: Mon, 13 Nov 2023 13:58:27 +0100 Subject: [PATCH 1/2] fix: use errors.Is instead of == for error comparison --- proxy/round_tripper/proxy_round_tripper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/round_tripper/proxy_round_tripper.go b/proxy/round_tripper/proxy_round_tripper.go index 470f1e2e..aa7e2e87 100644 --- a/proxy/round_tripper/proxy_round_tripper.go +++ b/proxy/round_tripper/proxy_round_tripper.go @@ -248,7 +248,7 @@ 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() From b41e3591e26180536dcf9e8e23b5f911db95b928 Mon Sep 17 00:00:00 2001 From: Maximilian Moehl Date: Mon, 13 Nov 2023 13:59:08 +0100 Subject: [PATCH 2/2] fix(proxy): only close body if it is not nil --- proxy/round_tripper/proxy_round_tripper.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/round_tripper/proxy_round_tripper.go b/proxy/round_tripper/proxy_round_tripper.go index aa7e2e87..49819b27 100644 --- a/proxy/round_tripper/proxy_round_tripper.go +++ b/proxy/round_tripper/proxy_round_tripper.go @@ -251,7 +251,9 @@ func (rt *roundTripper) RoundTrip(originalRequest *http.Request) (*http.Response 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