File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
4749type sshConfig struct {
@@ -96,6 +98,10 @@ func New(s *terraform.InstanceState) (*Communicator, error) {
9698
9799// Connect implementation of communicator.Communicator interface
98100func (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
192198func (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
You can’t perform that action at this time.
0 commit comments