From b51cd5406ac101b48f56ac0df4f0fedac4c65950 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Mon, 12 Oct 2015 18:12:22 -0700 Subject: [PATCH 1/2] Add explicit wait after Communicator.Download to make sure serveSingleCopy completes --- packer/rpc/communicator.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packer/rpc/communicator.go b/packer/rpc/communicator.go index abf841af8..525418ee2 100644 --- a/packer/rpc/communicator.go +++ b/packer/rpc/communicator.go @@ -2,11 +2,12 @@ package rpc import ( "encoding/gob" - "github.com/mitchellh/packer/packer" "io" "log" "net/rpc" "os" + + "github.com/mitchellh/packer/packer" ) // An implementation of packer.Communicator where the communicator is actually @@ -137,7 +138,13 @@ func (c *communicator) UploadDir(dst string, src string, exclude []string) error func (c *communicator) Download(path string, w io.Writer) (err error) { // Serve a single connection and a single copy streamId := c.mux.NextId() - go serveSingleCopy("downloadWriter", c.mux, streamId, w, nil) + + waitServer := make(chan bool) + + go func() { + serveSingleCopy("downloadWriter", c.mux, streamId, w, nil) + waitServer <- true + }() args := CommunicatorDownloadArgs{ Path: path, @@ -145,6 +152,9 @@ func (c *communicator) Download(path string, w io.Writer) (err error) { } err = c.client.Call("Communicator.Download", &args, new(interface{})) + + <-waitServer + return } From 48565440272157c20612026d0f6815a5b27ec6fd Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Mon, 12 Oct 2015 18:42:17 -0700 Subject: [PATCH 2/2] Add a comment to indicate why we're waiting on the channel --- packer/rpc/communicator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packer/rpc/communicator.go b/packer/rpc/communicator.go index 525418ee2..48c6ea09f 100644 --- a/packer/rpc/communicator.go +++ b/packer/rpc/communicator.go @@ -140,7 +140,6 @@ func (c *communicator) Download(path string, w io.Writer) (err error) { streamId := c.mux.NextId() waitServer := make(chan bool) - go func() { serveSingleCopy("downloadWriter", c.mux, streamId, w, nil) waitServer <- true @@ -151,8 +150,10 @@ func (c *communicator) Download(path string, w io.Writer) (err error) { WriterStreamId: streamId, } + // Start sending data to the RPC server err = c.client.Call("Communicator.Download", &args, new(interface{})) + // Wait for the RPC server to finish receiving the data before we return <-waitServer return