Add explicit wait after Communicator.Download to make sure serveSingleCopy completes

This commit is contained in:
Chris Bednarski 2015-10-12 18:12:22 -07:00
parent 4f59480adb
commit b51cd5406a
1 changed files with 12 additions and 2 deletions

View File

@ -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
}