Commit a6299fc4 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: log when client closes mux

parent fed689bb
...@@ -3,6 +3,7 @@ package rpc ...@@ -3,6 +3,7 @@ package rpc
import ( import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"io" "io"
"log"
"net/rpc" "net/rpc"
) )
...@@ -10,12 +11,19 @@ import ( ...@@ -10,12 +11,19 @@ import (
// Establishing a connection is up to the user, the Client can just // Establishing a connection is up to the user, the Client can just
// communicate over any ReadWriteCloser. // communicate over any ReadWriteCloser.
type Client struct { type Client struct {
mux *MuxConn mux *MuxConn
client *rpc.Client client *rpc.Client
closeMux bool
} }
func NewClient(rwc io.ReadWriteCloser) (*Client, error) { 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) { func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
...@@ -25,8 +33,9 @@ func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) { ...@@ -25,8 +33,9 @@ func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
} }
return &Client{ return &Client{
mux: mux, mux: mux,
client: rpc.NewClient(clientConn), client: rpc.NewClient(clientConn),
closeMux: false,
}, nil }, nil
} }
...@@ -35,6 +44,11 @@ func (c *Client) Close() error { ...@@ -35,6 +44,11 @@ func (c *Client) Close() error {
return err return err
} }
if c.closeMux {
log.Printf("[WARN] Client is closing mux")
return c.mux.Close()
}
return nil return nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment