Merge pull request #1907 from dongluochen/TcpConnectionLeak

Close TCP connections at disconnect
This commit is contained in:
Nishant Totla 2016-03-01 14:29:41 -08:00
commit e25da7e9bd
1 changed files with 10 additions and 0 deletions

View File

@ -218,10 +218,20 @@ func (e *Engine) Disconnect() {
// close the chan
close(e.stopCh)
e.client.StopAllMonitorEvents()
// close idle connections
if dc, ok := e.client.(*dockerclient.DockerClient); ok {
closeIdleConnections(dc.HTTPClient)
}
e.client = nopclient.NewNopClient()
e.emitEvent("engine_disconnect")
}
func closeIdleConnections(client *http.Client) {
if tr, ok := client.Transport.(*http.Transport); ok {
tr.CloseIdleConnections()
}
}
// isConnected returns true if the engine is connected to a remote docker API
func (e *Engine) isConnected() bool {
_, ok := e.client.(*nopclient.NopClient)