From 28a8293a22ed009774ba91383e9e6514d26784be Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 19 Aug 2013 16:25:00 -0700 Subject: [PATCH] packer/plugin: set TCP keep-alive on connection --- CHANGELOG.md | 1 + packer/plugin/client.go | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33fa28d68..bbe27c5f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ IMPROVEMENTS: BUG FIXES: +* core: TCP connection between plugin processes will keep-alive. [GH-312] * core: No more "unused key keep_input_artifact" for post processors [GH-310] * post-processor/vagrant: `output_path` templates now work again. diff --git a/packer/plugin/client.go b/packer/plugin/client.go index e380bf850..94513a8e2 100644 --- a/packer/plugin/client.go +++ b/packer/plugin/client.go @@ -10,6 +10,7 @@ import ( "io" "io/ioutil" "log" + "net" "net/rpc" "os" "os/exec" @@ -328,10 +329,14 @@ func (c *Client) rpcClient() (*rpc.Client, error) { return nil, err } - client, err := rpc.Dial("tcp", address) + conn, err := net.Dial("tcp", address) if err != nil { return nil, err } - return client, nil + // Make sure to set keep alive so that the connection doesn't die + tcpConn := conn.(*net.TCPConn) + tcpConn.SetKeepAlive(true) + + return rpc.NewClient(tcpConn), nil }