Skip to content

Commit 1f6902a

Browse files
committed
MTV-1482 | Fix main pod inventory watch NPE
Issue: When the request from main to the inventory pod fails the main pod crashes due to nil pointer. Fix: Move the request close to case when we get the response body. Signed-off-by: Martin Necas <mnecas@redhat.com>
1 parent 20b1d92 commit 1f6902a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

pkg/lib/inventory/web/client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ func (r *Client) Watch(url string, resource interface{}, h EventHandler) (status
255255
post := func(w *WatchReader) (pStatus int, pErr error) {
256256
socket, response, pErr := dialer.Dial(url, header)
257257
if response != nil {
258+
defer response.Body.Close()
258259
pStatus = response.StatusCode
259260
switch pStatus {
260261
case http.StatusOK,
@@ -265,9 +266,6 @@ func (r *Client) Watch(url string, resource interface{}, h EventHandler) (status
265266
return
266267
}
267268
}
268-
269-
defer response.Body.Close()
270-
271269
if pErr != nil {
272270
pErr = liberr.Wrap(
273271
pErr,

0 commit comments

Comments
 (0)