Skip to content

Commit d174317

Browse files
committed
Merge pull request #58 from allegro/agents_connection_leak_fix
Agents connection leak fix
2 parents 523192e + d429b19 commit d174317

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

consul/agents.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,23 @@ type ConcurrentAgents struct {
2323
agents map[string]*consulapi.Client
2424
config *ConsulConfig
2525
lock sync.Mutex
26+
client *http.Client
2627
}
2728

2829
func NewAgents(config *ConsulConfig) *ConcurrentAgents {
30+
client := &http.Client{
31+
Transport: &http.Transport{
32+
Proxy: http.ProxyFromEnvironment,
33+
TLSClientConfig: &tls.Config{
34+
InsecureSkipVerify: !config.SslVerify,
35+
},
36+
},
37+
Timeout: config.Timeout,
38+
}
2939
return &ConcurrentAgents{
3040
agents: make(map[string]*consulapi.Client),
3141
config: config,
42+
client: client,
3243
}
3344
}
3445

@@ -97,8 +108,9 @@ func (a *ConcurrentAgents) addAgent(agentHost string, agent *consulapi.Client) {
97108
func (a *ConcurrentAgents) createAgent(ipAddress string) (*consulapi.Client, error) {
98109
config := consulapi.DefaultConfig()
99110

111+
config.HttpClient = a.client
112+
100113
config.Address = fmt.Sprintf("%s:%s", ipAddress, a.config.Port)
101-
config.HttpClient.Timeout = a.config.Timeout
102114

103115
if a.config.Token != "" {
104116
config.Token = a.config.Token
@@ -108,14 +120,6 @@ func (a *ConcurrentAgents) createAgent(ipAddress string) (*consulapi.Client, err
108120
config.Scheme = "https"
109121
}
110122

111-
if !a.config.SslVerify {
112-
config.HttpClient.Transport = &http.Transport{
113-
TLSClientConfig: &tls.Config{
114-
InsecureSkipVerify: true,
115-
},
116-
}
117-
}
118-
119123
if a.config.Auth.Enabled {
120124
config.HttpAuth = &consulapi.HttpBasicAuth{
121125
Username: a.config.Auth.Username,

0 commit comments

Comments
 (0)