communicator/ssh: Disconnect() should also kill the actual connection
This commit is contained in:
parent
cde458d74f
commit
b486354a9c
|
@ -42,6 +42,8 @@ type Communicator struct {
|
||||||
config *sshConfig
|
config *sshConfig
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
address string
|
address string
|
||||||
|
|
||||||
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshConfig struct {
|
type sshConfig struct {
|
||||||
|
@ -96,6 +98,10 @@ func New(s *terraform.InstanceState) (*Communicator, error) {
|
||||||
|
|
||||||
// Connect implementation of communicator.Communicator interface
|
// Connect implementation of communicator.Communicator interface
|
||||||
func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
|
func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
|
||||||
|
// Grab a lock so we can modify our internal attributes
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
if c.conn != nil {
|
if c.conn != nil {
|
||||||
c.conn.Close()
|
c.conn.Close()
|
||||||
}
|
}
|
||||||
|
@ -190,8 +196,19 @@ func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
|
||||||
|
|
||||||
// Disconnect implementation of communicator.Communicator interface
|
// Disconnect implementation of communicator.Communicator interface
|
||||||
func (c *Communicator) Disconnect() error {
|
func (c *Communicator) Disconnect() error {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
if c.config.sshAgent != nil {
|
if c.config.sshAgent != nil {
|
||||||
return c.config.sshAgent.Close()
|
if err := c.config.sshAgent.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.conn != nil {
|
||||||
|
conn := c.conn
|
||||||
|
c.conn = nil
|
||||||
|
return conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue