Skip to content

Commit

Permalink
fix: Memory Leak in transport.tlsTransportCache (#2216)
Browse files Browse the repository at this point in the history
* fix: Memory Leak in transport.tlsTransportCache

* fix: Memory Leak in KymaSkrContextProvider

---------

Co-authored-by: Christoph Schwägerl <[email protected]>
  • Loading branch information
LeelaChacha and c-pius authored Jan 28, 2025
1 parent 7c1f6af commit 9dd89fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/declarative/v2/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func NewSingletonClients(info *ClusterInfo) (*SingletonClients, error) {
return nil, err
}

// Required to prevent memory leak by avoiding caching in transport.tlsTransportCache. SingletonClients are cached anyways.
info.Config.Proxy = http.ProxyFromEnvironment

httpClient, err := rest.HTTPClientFor(info.Config)
if err != nil {
return nil, fmt.Errorf("failed to initiliaze httpClient: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions internal/remote/skr_context_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"

apicorev1 "k8s.io/api/core/v1"
k8slabels "k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -64,6 +65,9 @@ func (k *KymaSkrContextProvider) Init(ctx context.Context, kyma types.Namespaced
restConfig.QPS = k.kcpClient.Config().QPS
restConfig.Burst = k.kcpClient.Config().Burst

// Required to prevent memory leak by avoiding caching in transport.tlsTransportCache. skrClients are cached anyways.
restConfig.Proxy = http.ProxyFromEnvironment

clnt, err := client.New(restConfig, client.Options{Scheme: k.kcpClient.Scheme()})
if err != nil {
return fmt.Errorf("failed to create lookup client: %w", err)
Expand Down

0 comments on commit 9dd89fb

Please sign in to comment.