Skip to content

Commit 7fc5ee8

Browse files
committed
bugfix (agent): fixes to agent/utils/download.go and agent/utils/req.go to close idle connections
1 parent 571c6e4 commit 7fc5ee8

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

agent/utils/download.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ func DownloadFile(url string, headers map[string]string, fileName string, path s
1818
req.Header.Add(key, value)
1919
}
2020

21-
client := &http.Client{}
22-
client.Transport = &http.Transport{
23-
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTlsVerification},
21+
tr := &http.Transport{
22+
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTlsVerification},
2423
DisableCompression: true,
2524
}
25+
client := &http.Client{Transport: tr}
26+
defer tr.CloseIdleConnections()
2627

2728
resp, err := client.Do(req)
2829
if err != nil {

agent/utils/req.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ func DoReq[response any](url string, data []byte, method string, headers map[str
2121
req.Header.Add(k, v)
2222
}
2323

24-
client := &http.Client{}
25-
client.Transport = &http.Transport{
24+
tr := &http.Transport{
2625
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTlsVerification},
2726
}
27+
client := &http.Client{Transport: tr}
28+
defer tr.CloseIdleConnections()
2829

2930
resp, err := client.Do(req)
3031
if err != nil {

0 commit comments

Comments
 (0)