Skip to content

Commit 5cdc316

Browse files
authored
fix: Fix the problem that some request connections are not released (#8329)
1 parent e352de6 commit 5cdc316

11 files changed

Lines changed: 15 additions & 2 deletions

File tree

agent/utils/cloud_storage/client/ali.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ func (a aliClient) uploadPart(uri string, reader io.Reader) error {
403403
return err
404404
}
405405
client := &http.Client{}
406+
defer client.CloseIdleConnections()
406407
response, err := client.Do(req)
407408
if err != nil {
408409
return err
@@ -428,6 +429,7 @@ func (a aliClient) handleDownload(uri string, target string) error {
428429
req.Header.Add("origin", "https://www.aliyundrive.com")
429430
req.Header.Add("referer", "https://www.aliyundrive.com/")
430431
client := &http.Client{}
432+
defer client.CloseIdleConnections()
431433
response, err := client.Do(req)
432434
if err != nil {
433435
return err

agent/utils/cloud_storage/client/google_drive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ func (g *googleDriveClient) handleDownload(urlItem string, target string) error
226226
Proxy: http.ProxyURL(proxyURL),
227227
},
228228
}
229+
defer client.CloseIdleConnections()
229230
response, err := client.Do(req)
230231
if err != nil {
231232
return err

agent/utils/cloud_storage/client/onedrive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func RefreshToken(grantType string, tokenType string, varMap map[string]interfac
213213
}
214214
data.Set("redirect_uri", loadParamFromVars("redirect_uri", varMap))
215215
client := &http.Client{}
216+
defer client.CloseIdleConnections()
216217
url := "https://login.microsoftonline.com/common/oauth2/v2.0/token"
217218
if isCN == "true" {
218219
url = "https://login.chinacloudapi.cn/common/oauth2/v2.0/token"

agent/utils/files/file_op.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ func (f FileOp) DownloadFileWithProcess(url, dst, key string, ignoreCertificate
274274
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
275275
}
276276
}
277+
defer client.CloseIdleConnections()
277278
request, err := http.NewRequest("GET", url, nil)
278279
if err != nil {
279280
return nil

agent/utils/req_helper/core.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func PostLocalCore(url string) error {
3030
return err
3131
}
3232
client := &http.Client{}
33+
defer client.CloseIdleConnections()
3334
resp, err := client.Do(req)
3435
if err != nil {
3536
return err

agent/utils/req_helper/request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func HandleGet(url string) (*http.Response, error) {
1919
Timeout: time.Second * 300,
2020
}
2121
client.Transport = loadRequestTransport()
22+
defer client.CloseIdleConnections()
2223

2324
req, err := http.NewRequestWithContext(context.Background(), "GET", url, nil)
2425
if err != nil {

agent/utils/ssl/acme.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func getZeroSSLEabCredentials(email string) (*zeroSSLRes, error) {
181181
req.Header.Set("Content-Type", "application/json")
182182

183183
client := &http.Client{}
184+
defer client.CloseIdleConnections()
184185
resp, err := client.Do(req)
185186
if err != nil {
186187
return nil, err

core/utils/cloud_storage/client/ali.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func (a aliClient) uploadPart(uri string, reader io.Reader) error {
301301
return err
302302
}
303303
client := &http.Client{}
304+
defer client.CloseIdleConnections()
304305
response, err := client.Do(req)
305306
if err != nil {
306307
return err

core/utils/cloud_storage/client/onedrive.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func RefreshToken(grantType string, tokenType string, varMap map[string]interfac
123123
}
124124
data.Set("redirect_uri", loadParamFromVars("redirect_uri", varMap))
125125
client := &http.Client{}
126+
defer client.CloseIdleConnections()
126127
url := "https://login.microsoftonline.com/common/oauth2/v2.0/token"
127128
if isCN == "true" {
128129
url = "https://login.chinacloudapi.cn/common/oauth2/v2.0/token"

core/utils/req_helper/proxy_local/req_to_local.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"github.com/1Panel-dev/1Panel/core/app/dto"
9-
"github.com/1Panel-dev/1Panel/core/i18n"
108
"io"
119
"net"
1210
"net/http"
1311
"net/url"
1412
"os"
1513
"strings"
14+
15+
"github.com/1Panel-dev/1Panel/core/app/dto"
16+
"github.com/1Panel-dev/1Panel/core/i18n"
1617
)
1718

1819
func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, error) {
@@ -31,6 +32,7 @@ func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, erro
3132
client := &http.Client{
3233
Transport: transport,
3334
}
35+
defer client.CloseIdleConnections()
3436
parsedURL, err := url.Parse("http://unix")
3537
if err != nil {
3638
return nil, fmt.Errorf("handle url Parse failed, err: %v \n", err)

0 commit comments

Comments
 (0)