From a6299fc49a67a97a2c091a0a5b4bed4cf46d26a5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 Dec 2013 16:33:43 -0800 Subject: [PATCH] packer/rpc: log when client closes mux --- packer/rpc/client.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packer/rpc/client.go b/packer/rpc/client.go index c9ddc5f57..50d445ef1 100644 --- a/packer/rpc/client.go +++ b/packer/rpc/client.go @@ -3,6 +3,7 @@ package rpc import ( "github.com/mitchellh/packer/packer" "io" + "log" "net/rpc" ) @@ -10,12 +11,19 @@ import ( // Establishing a connection is up to the user, the Client can just // communicate over any ReadWriteCloser. type Client struct { - mux *MuxConn - client *rpc.Client + mux *MuxConn + client *rpc.Client + closeMux bool } func NewClient(rwc io.ReadWriteCloser) (*Client, error) { - return NewClientWithMux(NewMuxConn(rwc), 0) + result, err := NewClientWithMux(NewMuxConn(rwc), 0) + if err != nil { + return nil, err + } + + result.closeMux = true + return result, err } func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) { @@ -25,8 +33,9 @@ func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) { } return &Client{ - mux: mux, - client: rpc.NewClient(clientConn), + mux: mux, + client: rpc.NewClient(clientConn), + closeMux: false, }, nil } @@ -35,6 +44,11 @@ func (c *Client) Close() error { return err } + if c.closeMux { + log.Printf("[WARN] Client is closing mux") + return c.mux.Close() + } + return nil }