Skip to content

Commit ac1acdf

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

api/client.go

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type Client interface {
7979
Do(context.Context, *http.Request) (*http.Response, []byte, error)
8080
}
8181

82+
type closeIdler interface {
83+
CloseIdleConnections()
84+
}
85+
8286
// NewClient returns a new Client.
8387
//
8488
// It is safe to use the returned Client from multiple goroutines.
@@ -99,6 +103,10 @@ func NewClient(cfg Config) (Client, error) {
99103
}, nil
100104
}
101105

106+
func ClientCloseIdler(cl Client) {
107+
cl.(closeIdler).CloseIdleConnections()
108+
}
109+
102110
type httpClient struct {
103111
endpoint *url.URL
104112
client http.Client
@@ -118,6 +126,10 @@ func (c *httpClient) URL(ep string, args map[string]string) *url.URL {
118126
return &u
119127
}
120128

129+
func (c *httpClient) CloseIdleConnections() {
130+
c.client.CloseIdleConnections()
131+
}
132+
121133
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
122134
if ctx != nil {
123135
req = req.WithContext(ctx)

api/prometheus/v1/api_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,9 @@ type apiClientTest struct {
12631263
expectedWarnings Warnings
12641264
}
12651265

1266+
func (c *testClient) CloseIdleConnections() {
1267+
}
1268+
12661269
func (c *testClient) URL(ep string, args map[string]string) *url.URL {
12671270
return nil
12681271
}

0 commit comments

Comments
 (0)