Skip to content

Commit

Permalink
keystore: fix conn leak in {AWS,GCP,Fortanx,Gemalto} backend
Browse files Browse the repository at this point in the history
This commit fixes a TCP conn leak in the AWS, GCP, Fortanix and
Gemalto KMS backend. Due to a missing `http.Response.Body.Close`
call, the status check in these backends accumulated TCP connections
that are not closed by the runtime.

This resource leak can cause OOM issues.

Fixes #445

Signed-off-by: Andreas Auernhammer <[email protected]>
  • Loading branch information
aead committed Mar 5, 2024
1 parent 8ecd396 commit 4ac5aef
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion internal/keystore/aws/secrets-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
}

start := time.Now()
if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
defer resp.Body.Close()

return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/keystore/azure/key-vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
resp.Body.Close()
defer resp.Body.Close()

return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down
5 changes: 4 additions & 1 deletion internal/keystore/fortanix/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
}

start := time.Now()
if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
defer resp.Body.Close()

return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down
5 changes: 4 additions & 1 deletion internal/keystore/gcp/secret-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,12 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
}

start := time.Now()
if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
defer resp.Body.Close()

return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down
5 changes: 4 additions & 1 deletion internal/keystore/gemalto/key-secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
}

start := time.Now()
if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
defer resp.Body.Close()

return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down

0 comments on commit 4ac5aef

Please sign in to comment.