Skip to content

Commit

Permalink
Rework the response body close()
Browse files Browse the repository at this point in the history
  • Loading branch information
ffurano authored and gmgigi96 committed Oct 30, 2023
1 parent b9b78a5 commit 09e0b04
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
log.Debug().Str("func", "PUTFile").Msg("sending req")

resp, err := c.doReq(req, remoteuser)
if resp != nil {
resp.Body.Close()
}

// Let's support redirections... and if we retry we retry at the same FST
if resp != nil && resp.StatusCode == 307 {
Expand Down Expand Up @@ -424,6 +421,9 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos

log.Debug().Str("func", "PUTFile").Str("location", loc.String()).Msg("redirection")
nredirs++
if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
resp = nil
err = nil
continue
Expand All @@ -432,12 +432,17 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
// And get an error code (if error) that is worth propagating
e := c.getRespError(resp, err)
if e != nil {
if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
if os.IsTimeout(e) {
ntries++
log.Warn().Str("func", "PUTFile").Str("url", finalurl).Str("err", e.Error()).Int("try", ntries).Msg("recoverable network timeout")
continue
}

log.Error().Str("func", "PUTFile").Str("url", finalurl).Str("err", e.Error()).Msg("")

return e
}

Expand All @@ -446,6 +451,9 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
return errtypes.NotFound(fmt.Sprintf("url: %s", finalurl))
}

if (resp != nil) && (resp.Body != nil) {
resp.Body.Close()
}
return nil
}
}
Expand Down

0 comments on commit 09e0b04

Please sign in to comment.