From 2408826f26fb7c883dfe7838f969a814c1b4413a Mon Sep 17 00:00:00 2001 From: zyxkad Date: Fri, 23 Feb 2024 10:10:49 -0700 Subject: [PATCH] fix memory leak issue close #30 --- cluster.go | 16 ++++++++++------ storage_webdav.go | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cluster.go b/cluster.go index 712e4f95..8a0ff4da 100644 --- a/cluster.go +++ b/cluster.go @@ -66,7 +66,6 @@ type Cluster struct { storageWeights []uint storageTotalWeight uint cache Cache - httpCache Cache apiHmacKey []byte stats Stats @@ -88,8 +87,9 @@ type Cluster struct { fileset map[string]int64 authToken *ClusterToken - client *http.Client - bufSlots *BufSlots + client *http.Client + cachedCli *http.Client + bufSlots *BufSlots handlerAPIv0 http.Handler handlerAPIv1 http.Handler @@ -112,8 +112,9 @@ func NewCluster( } } + cachedTransport := transport if cache != NoCache { - transport = &httpcache.Transport{ + cachedTransport = &httpcache.Transport{ Transport: transport, Cache: WrapToHTTPCache(NewCacheWithNamespace(cache, "http@")), } @@ -139,6 +140,9 @@ func NewCluster( client: &http.Client{ Transport: transport, }, + cachedCli: &http.Client{ + Transport: cachedTransport, + }, } close(cr.disabled) @@ -591,7 +595,7 @@ func (cr *Cluster) GetFileList(ctx context.Context) (files []FileInfo, err error if err != nil { return } - res, err := cr.client.Do(req) + res, err := cr.cachedCli.Do(req) if err != nil { return } @@ -618,7 +622,7 @@ func (cr *Cluster) GetConfig(ctx context.Context) (cfg *OpenbmclapiAgentConfig, if err != nil { return } - res, err := cr.client.Do(req) + res, err := cr.cachedCli.Do(req) if err != nil { return } diff --git a/storage_webdav.go b/storage_webdav.go index 8784bd16..5d87cabe 100644 --- a/storage_webdav.go +++ b/storage_webdav.go @@ -64,7 +64,7 @@ func (o *WebDavStorageOption) MarshalYAML() (any, error) { func (o *WebDavStorageOption) UnmarshalYAML(n *yaml.Node) (err error) { // set default values - o.MaxConn = 24 + o.MaxConn = 64 o.MaxUploadRate = 0 o.MaxDownloadRate = 0 o.PreGenMeasures = false