Close TCP connections at disconnect.

Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
Dong Chen 2016-02-29 10:23:37 -08:00
parent 984aab2999
commit 87a03b9157
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)