⚡ when high concurrency occurs, the connection is full and the connection is rejected.
Signed-off-by: cuisongliu <cuisongliu@qq.com>
This commit is contained in:
parent
7d3be80a44
commit
402957092e
|
@ -79,6 +79,10 @@ type Client interface {
|
||||||
Do(context.Context, *http.Request) (*http.Response, []byte, error)
|
Do(context.Context, *http.Request) (*http.Response, []byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type closeIdler interface {
|
||||||
|
CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|
||||||
// NewClient returns a new Client.
|
// NewClient returns a new Client.
|
||||||
//
|
//
|
||||||
// It is safe to use the returned Client from multiple goroutines.
|
// It is safe to use the returned Client from multiple goroutines.
|
||||||
|
@ -99,6 +103,10 @@ func NewClient(cfg Config) (Client, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClientCloseIdler(cl Client) {
|
||||||
|
cl.(closeIdler).CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|
||||||
type httpClient struct {
|
type httpClient struct {
|
||||||
endpoint *url.URL
|
endpoint *url.URL
|
||||||
client http.Client
|
client http.Client
|
||||||
|
@ -118,6 +126,10 @@ func (c *httpClient) URL(ep string, args map[string]string) *url.URL {
|
||||||
return &u
|
return &u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *httpClient) CloseIdleConnections() {
|
||||||
|
c.client.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
|
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
|
||||||
if ctx != nil {
|
if ctx != nil {
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
|
|
Loading…
Reference in New Issue