Skip to content

Commit

Permalink
Always close sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
jesushernandez committed Jul 14, 2021
1 parent 6ca677a commit e967e8e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ func (c *Client) apiRequest(ctx context.Context, method string, endpoint string,
}
log.Debugf("%s got status code %d for (%s %s)", c, res.StatusCode, method, url)

defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, res.StatusCode, fmt.Errorf("invalid response received (%s)", res.Status)
}

responseBody, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()

return responseBody, res.StatusCode, nil
}
Expand Down
4 changes: 2 additions & 2 deletions plot/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func (p *Plot) getDownloadSize() (fileSize int64, err error) {
err = errors.Wrap(err, "error while making the HTTP request to download the file")
return
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("invalid status code returned (%d) while trying to get download size", resp.StatusCode)
Expand Down Expand Up @@ -561,7 +562,7 @@ func (p *Plot) Download(ctx context.Context) (err error) {
err = errors.Wrap(err, "error while making the HTTP request to download the file")
return
}

defer resp.Body.Close()
if resp.StatusCode != expectedStatusCode {
err = fmt.Errorf("invalid status code returned (%d)", resp.StatusCode)
return
Expand All @@ -582,7 +583,6 @@ func (p *Plot) Download(ctx context.Context) (err error) {
)

defer func() {
resp.Body.Close()
filebuff.Flush()
done <- err
}()
Expand Down

0 comments on commit e967e8e

Please sign in to comment.