Skip to content

Commit b59f66e

Browse files
andrewgilbert12abg
authored andcommitted
Use a single http client for switchboard
- We were running out of file handlers similar to [this issue](golang/go#24719) [#164174371] Signed-off-by: Andrew Garner <[email protected]>
1 parent b998094 commit b59f66e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/replication-canary/switchboard/client.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
)
1414

1515
type Client struct {
16-
rootURL string
17-
username string
18-
password string
19-
skipSSLCertVerify bool
20-
logger lager.Logger
16+
client *http.Client
17+
rootURL string
18+
username string
19+
password string
20+
logger lager.Logger
2121
}
2222

2323
func NewClient(
@@ -28,11 +28,18 @@ func NewClient(
2828
logger lager.Logger,
2929
) *Client {
3030
return &Client{
31-
rootURL: rootURL,
32-
username: username,
33-
password: password,
34-
skipSSLCertVerify: skipSSLCertVerify,
35-
logger: logger,
31+
client: &http.Client{
32+
Timeout: time.Second * 5,
33+
Transport: &http.Transport{
34+
TLSClientConfig: &tls.Config{
35+
InsecureSkipVerify: skipSSLCertVerify,
36+
},
37+
},
38+
},
39+
rootURL: rootURL,
40+
username: username,
41+
password: password,
42+
logger: logger,
3643
}
3744
}
3845

@@ -76,7 +83,7 @@ func (c *Client) sendClusterTrafficRequest(enabled enable, message string) error
7683
"trafficEnabled": enabled,
7784
"message": message,
7885
})
79-
res, err := c.client().Do(req)
86+
res, err := c.client.Do(req)
8087
if err != nil {
8188
c.logger.Debug("error making request to proxy", lager.Data{
8289
"errorMessage": err.Error(),
@@ -106,17 +113,6 @@ func (c *Client) sendClusterTrafficRequest(enabled enable, message string) error
106113

107114
type enable bool
108115

109-
func (c *Client) client() *http.Client {
110-
return &http.Client{
111-
Timeout: time.Second * 5,
112-
Transport: &http.Transport{
113-
TLSClientConfig: &tls.Config{
114-
InsecureSkipVerify: c.skipSSLCertVerify,
115-
},
116-
},
117-
}
118-
}
119-
120116
func (c *Client) ActiveBackendHost() (string, error) {
121117
u := c.rootURL + "/v0/backends"
122118

@@ -136,7 +132,7 @@ func (c *Client) ActiveBackendHost() (string, error) {
136132
"method": "GET",
137133
"url": req.URL,
138134
})
139-
res, err := c.client().Do(req)
135+
res, err := c.client.Do(req)
140136
if err != nil {
141137
c.logger.Debug("error making request to proxy", lager.Data{
142138
"errorMessage": err.Error(),

0 commit comments

Comments
 (0)