From 00053643632c14bbed790f404214f3b3bc80dd31 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Sun, 16 Oct 2022 01:43:05 +0800 Subject: [PATCH] Fix NPE (#112999) * Fix NPE * bump version --- test/images/agnhost/VERSION | 2 +- .../images/agnhost/no-snat-test-proxy/main.go | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index d920eceb604..2a43146444b 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.41 +2.42 diff --git a/test/images/agnhost/no-snat-test-proxy/main.go b/test/images/agnhost/no-snat-test-proxy/main.go index c5b16718faf..5d30116f4ca 100644 --- a/test/images/agnhost/no-snat-test-proxy/main.go +++ b/test/images/agnhost/no-snat-test-proxy/main.go @@ -79,16 +79,18 @@ func checknosnat(w http.ResponseWriter, req *http.Request) { if err != nil { w.WriteHeader(500) fmt.Fprintf(w, "error querying %q, err: %v", url, err) - } else { - body, err := io.ReadAll(resp.Body) - if err != nil { - w.WriteHeader(500) - fmt.Fprintf(w, "error reading body of response from %q, err: %v", url, err) - } else { - // Respond the same status code and body as /checknosnat on the internal Pod - w.WriteHeader(resp.StatusCode) - w.Write(body) - } + return } - resp.Body.Close() + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + w.WriteHeader(500) + fmt.Fprintf(w, "error reading body of response from %q, err: %v", url, err) + return + } + + // Respond the same status code and body as /checknosnat on the internal Pod + w.WriteHeader(resp.StatusCode) + w.Write(body) }