Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit b486354

Browse files
committed
communicator/ssh: Disconnect() should also kill the actual connection
1 parent cde458d commit b486354

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

communicator/ssh/communicator.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ type Communicator struct {
4242
config *sshConfig
4343
conn net.Conn
4444
address string
45+
46+
lock sync.Mutex
4547
}
4648

4749
type sshConfig struct {
@@ -96,6 +98,10 @@ func New(s *terraform.InstanceState) (*Communicator, error) {
9698

9799
// Connect implementation of communicator.Communicator interface
98100
func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
101+
// Grab a lock so we can modify our internal attributes
102+
c.lock.Lock()
103+
defer c.lock.Unlock()
104+
99105
if c.conn != nil {
100106
c.conn.Close()
101107
}
@@ -190,8 +196,19 @@ func (c *Communicator) Connect(o terraform.UIOutput) (err error) {
190196

191197
// Disconnect implementation of communicator.Communicator interface
192198
func (c *Communicator) Disconnect() error {
199+
c.lock.Lock()
200+
defer c.lock.Unlock()
201+
193202
if c.config.sshAgent != nil {
194-
return c.config.sshAgent.Close()
203+
if err := c.config.sshAgent.Close(); err != nil {
204+
return err
205+
}
206+
}
207+
208+
if c.conn != nil {
209+
conn := c.conn
210+
c.conn = nil
211+
return conn.Close()
195212
}
196213

197214
return nil

0 commit comments

Comments
 (0)