Skip to content

Commit

Permalink
fix memory leak issue
Browse files Browse the repository at this point in the history
close #30
  • Loading branch information
zyxkad committed Feb 23, 2024
1 parent d36ef5e commit 2408826
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ type Cluster struct {
storageWeights []uint
storageTotalWeight uint
cache Cache
httpCache Cache
apiHmacKey []byte

stats Stats
Expand All @@ -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
Expand All @@ -112,8 +112,9 @@ func NewCluster(
}
}

cachedTransport := transport
if cache != NoCache {
transport = &httpcache.Transport{
cachedTransport = &httpcache.Transport{
Transport: transport,
Cache: WrapToHTTPCache(NewCacheWithNamespace(cache, "http@")),
}
Expand All @@ -139,6 +140,9 @@ func NewCluster(
client: &http.Client{
Transport: transport,
},
cachedCli: &http.Client{
Transport: cachedTransport,
},
}
close(cr.disabled)

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion storage_webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2408826

Please sign in to comment.