Skip to content

Commit

Permalink
entrust: Close body to avoid some conn leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis Eleuch committed Aug 27, 2024
1 parent c07d23a commit 8cd46f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/http/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (r *Retry) Do(req *http.Request) (*http.Response, error) {

resp, err := r.Client.Do(req)
for N > 0 && (isTemporary(err) || (resp != nil && resp.StatusCode >= http.StatusInternalServerError)) {
if resp != nil {
resp.Body.Close()
}

N--
var delay time.Duration
switch {
Expand Down
3 changes: 3 additions & 0 deletions internal/keystore/entrust/keycontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func (kc *KeyControl) Status(ctx context.Context) (kes.KeyStoreState, error) {
Err: fmt.Errorf("keycontrol: failed to fetch status: %v", err),
}
}
defer resp.Body.Close()
latency := time.Since(start)

if resp.StatusCode != http.StatusOK {
Expand Down Expand Up @@ -295,6 +296,7 @@ func (kc *KeyControl) Delete(ctx context.Context, name string) error {
if err != nil {
return fmt.Errorf("keycontrol: failed to delete key: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return parseErrorResponse(resp)
}
Expand Down Expand Up @@ -380,6 +382,7 @@ func (kc *KeyControl) List(ctx context.Context, prefix string, n int) ([]string,
if err != nil {
return nil, "", fmt.Errorf("keycontrol: failed to list keys: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, "", parseErrorResponse(resp)
}
Expand Down

0 comments on commit 8cd46f5

Please sign in to comment.