From 9d55fa7f46d48425a3aed739875d198f600445fb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 21 Feb 2014 14:45:40 -0800 Subject: [PATCH] communicator/ssh: set TCP keep-alive [GH-872] --- CHANGELOG.md | 1 + communicator/ssh/connect.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e5eae8f8..0f9e285c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ BUG FIXES: checksum type is "none" * builder/virtualbox,vmware/qemu: Support for additional scancodes for `boot_command` such as ``, ``, ``, etc. [GH-808] +* communicator/ssh: Send TCP keep-alives on connections. [GH-872] * provisioners/ansible-local: Properly upload custom playbooks. [GH-829] ## 0.5.1 (01/02/2014) diff --git a/communicator/ssh/connect.go b/communicator/ssh/connect.go index 00002dc70..bee446baa 100644 --- a/communicator/ssh/connect.go +++ b/communicator/ssh/connect.go @@ -10,6 +10,13 @@ import ( // is suitable for use with the SSH communicator configuration. func ConnectFunc(network, addr string) func() (net.Conn, error) { return func() (net.Conn, error) { - return net.DialTimeout(network, addr, 15*time.Second) + c, err := net.DialTimeout(network, addr, 15*time.Second) + if err != nil { + return nil, err + } + + if tcpConn, ok := c.(*net.TCPConn); ok { + tcpConn.SetKeepAlive(true) + } } }