diff --git a/cluster/engine.go b/cluster/engine.go index e04f6f7080..74e2d82d3c 100644 --- a/cluster/engine.go +++ b/cluster/engine.go @@ -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)