Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f1e4e5

Browse files
committedMay 16, 2024·
⚡ when high concurrency occurs, the connection is full and the connection is rejected.
Signed-off-by: cuisongliu <[email protected]>
1 parent 7d3be80 commit 9f1e4e5

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed
 

‎api/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (cfg *Config) validate() error {
7777
type Client interface {
7878
URL(ep string, args map[string]string) *url.URL
7979
Do(context.Context, *http.Request) (*http.Response, []byte, error)
80+
CloseIdleConnections()
8081
}
8182

8283
// NewClient returns a new Client.
@@ -118,6 +119,10 @@ func (c *httpClient) URL(ep string, args map[string]string) *url.URL {
118119
return &u
119120
}
120121

122+
func (c *httpClient) CloseIdleConnections() {
123+
c.client.CloseIdleConnections()
124+
}
125+
121126
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
122127
if ctx != nil {
123128
req = req.WithContext(ctx)

‎api/prometheus/v1/api.go

+5
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ type Warnings []string
13421342
// apiClient wraps a regular client and processes successful API responses.
13431343
// Successful also includes responses that errored at the API level.
13441344
type apiClient interface {
1345+
CloseIdleConnections()
13451346
URL(ep string, args map[string]string) *url.URL
13461347
Do(context.Context, *http.Request) (*http.Response, []byte, Warnings, error)
13471348
DoGetFallback(ctx context.Context, u *url.URL, args url.Values) (*http.Response, []byte, Warnings, error)
@@ -1374,6 +1375,10 @@ func errorTypeAndMsgFor(resp *http.Response) (ErrorType, string) {
13741375
return ErrBadResponse, fmt.Sprintf("bad response code %d", resp.StatusCode)
13751376
}
13761377

1378+
func (h *apiClientImpl) CloseIdleConnections() {
1379+
h.client.CloseIdleConnections()
1380+
}
1381+
13771382
func (h *apiClientImpl) URL(ep string, args map[string]string) *url.URL {
13781383
return h.client.URL(ep, args)
13791384
}

‎api/prometheus/v1/api_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (c *apiTestClient) URL(ep string, args map[string]string) *url.URL {
6262
return u
6363
}
6464

65+
func (c *apiTestClient) CloseIdleConnections() {
66+
}
67+
6568
func (c *apiTestClient) Do(_ context.Context, req *http.Request) (*http.Response, []byte, Warnings, error) {
6669
test := c.curTest
6770

@@ -1263,6 +1266,9 @@ type apiClientTest struct {
12631266
expectedWarnings Warnings
12641267
}
12651268

1269+
func (c *testClient) CloseIdleConnections() {
1270+
}
1271+
12661272
func (c *testClient) URL(ep string, args map[string]string) *url.URL {
12671273
return nil
12681274
}
@@ -1734,6 +1740,10 @@ type httpTestClient struct {
17341740
client http.Client
17351741
}
17361742

1743+
func (c *httpTestClient) CloseIdleConnections() {
1744+
c.client.CloseIdleConnections()
1745+
}
1746+
17371747
func (c *httpTestClient) URL(ep string, args map[string]string) *url.URL {
17381748
return nil
17391749
}

0 commit comments

Comments
 (0)
Please sign in to comment.