<#7048 fix(flytectl): handle NewRequest error and ...
# flyte-github
a
#7048 fix(flytectl): handle NewRequest error and close response body in SendRequest Pull request opened by themavik Summary Two bugs in
SendRequest
in `flytectl/pkg/util/util.go`: 1. Ignored
http.NewRequest
error causes nil pointer panic
req, _ := http.NewRequest(method, url, option) response, err := client.Do(req) // panics if req is nil If the method or URL is invalid,
http.NewRequest
returns an error and a nil
*Request
. The error was silently discarded with
_
, and
<http://client.Do|client.Do>(nil)
panics. Fix: Check the error from
http.NewRequest
and return it. 2. HTTP response body leaked on non-200 status When the response has a non-200 status code, the function returns an error but never closes
response.Body
, leaking the underlying TCP connection. Fix: Close
response.Body
before returning the error. Testing • Existing test
TestSendRequest
with
"<htp://github.com>"
now returns a proper error from
NewRequest
instead of relying on
<http://client.Do|client.Do>
to fail • No behavioral change for callers on the success path flyteorg/flyte