Skip to content

Commit

Permalink
Merge pull request #58 from allegro/agents_connection_leak_fix
Browse files Browse the repository at this point in the history
Agents connection leak fix
  • Loading branch information
janisz committed Feb 16, 2016
2 parents 523192e + d429b19 commit d174317
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions consul/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ type ConcurrentAgents struct {
agents map[string]*consulapi.Client
config *ConsulConfig
lock sync.Mutex
client *http.Client
}

func NewAgents(config *ConsulConfig) *ConcurrentAgents {
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !config.SslVerify,
},
},
Timeout: config.Timeout,
}
return &ConcurrentAgents{
agents: make(map[string]*consulapi.Client),
config: config,
client: client,
}
}

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

config.HttpClient = a.client

config.Address = fmt.Sprintf("%s:%s", ipAddress, a.config.Port)
config.HttpClient.Timeout = a.config.Timeout

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

if !a.config.SslVerify {
config.HttpClient.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
}

if a.config.Auth.Enabled {
config.HttpAuth = &consulapi.HttpBasicAuth{
Username: a.config.Auth.Username,
Expand Down

0 comments on commit d174317

Please sign in to comment.