From 5dd8ae45c70876dc478af0eee856ff9ac4845f5b Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 2 Jul 2015 03:55:18 -0700 Subject: [PATCH] Cleanup some resources we may have created --- communicator/ssh/communicator.go | 6 ++++++ communicator/ssh/communicator_test.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index f05f6e46e..d1be89e64 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -308,6 +308,12 @@ func (c *comm) reconnect() (err error) { // We don't need to do anything here. We just want select to block until // we connect or timeout. case <-timeoutExceeded: + if c.conn != nil { + c.conn.Close() + } + if sshConn != nil { + sshConn.Close() + } return ErrHandshakeTimeout } diff --git a/communicator/ssh/communicator_test.go b/communicator/ssh/communicator_test.go index 6398bd713..b0bc03508 100644 --- a/communicator/ssh/communicator_test.go +++ b/communicator/ssh/communicator_test.go @@ -111,8 +111,8 @@ func newMockBrokenServer(t *testing.T) string { defer c.Close() // This should block for a period of time longer than our timeout in // the test case. That way we invoke a failure scenario. - time.Sleep(5 * time.Second) t.Log("Block on handshaking for SSH connection") + time.Sleep(5 * time.Second) }() return l.Addr().String()