diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index 6f729e9f6..9d6570a94 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -205,9 +205,14 @@ func (c *comm) Download(string, io.Writer) error { panic("not implemented yet") } -func (c *comm) newSession() (*ssh.Session, error) { +func (c *comm) newSession() (session *ssh.Session, err error) { log.Println("opening new ssh session") - session, err := c.client.NewSession() + if c.client == nil { + err = errors.New("client not available") + } else { + session, err = c.client.NewSession() + } + if err != nil { log.Printf("ssh session open error: '%s', attempting reconnect", err) if err := c.reconnect(); err != nil { @@ -225,6 +230,10 @@ func (c *comm) reconnect() (err error) { c.conn.Close() } + // Set the conn and client to nil since we'll recreate it + c.conn = nil + c.client = nil + log.Printf("reconnecting to TCP connection for SSH") c.conn, err = c.config.Connection() if err != nil {