From 267460c20b7e7b11291fa10f727e18b37579695f Mon Sep 17 00:00:00 2001 From: Shijiang Wei Date: Wed, 16 Sep 2015 20:28:07 +0800 Subject: [PATCH] error should be checked earlier in the hijack function Signed-off-by: Shijiang Wei Upstream-commit: f2d978ccf9ae29aa8ac06791ac0ffeceb4167d9b Component: engine --- components/engine/api/client/hijack.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/engine/api/client/hijack.go b/components/engine/api/client/hijack.go index a65468074c..14e3bc58f7 100644 --- a/components/engine/api/client/hijack.go +++ b/components/engine/api/client/hijack.go @@ -156,6 +156,13 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea req.Host = cli.addr dial, err := cli.dial() + if err != nil { + if strings.Contains(err.Error(), "connection refused") { + return fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?") + } + return err + } + // When we set up a TCP connection for hijack, there could be long periods // of inactivity (a long running command with no output) that in certain // network setups may cause ECONNTIMEOUT, leaving the client in an unknown @@ -165,12 +172,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea tcpConn.SetKeepAlive(true) tcpConn.SetKeepAlivePeriod(30 * time.Second) } - if err != nil { - if strings.Contains(err.Error(), "connection refused") { - return fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?") - } - return err - } + clientconn := httputil.NewClientConn(dial, nil) defer clientconn.Close()