Merge pull request #2825 from mitchellh/b-2793
Add explicit wait after Communicator.Download to make sure serveSingleCopy completes
This commit is contained in:
commit
445595c6b5
|
@ -2,11 +2,12 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"github.com/mitchellh/packer/packer"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/mitchellh/packer/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An implementation of packer.Communicator where the communicator is actually
|
// An implementation of packer.Communicator where the communicator is actually
|
||||||
|
@ -137,14 +138,24 @@ func (c *communicator) UploadDir(dst string, src string, exclude []string) error
|
||||||
func (c *communicator) Download(path string, w io.Writer) (err error) {
|
func (c *communicator) Download(path string, w io.Writer) (err error) {
|
||||||
// Serve a single connection and a single copy
|
// Serve a single connection and a single copy
|
||||||
streamId := c.mux.NextId()
|
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{
|
args := CommunicatorDownloadArgs{
|
||||||
Path: path,
|
Path: path,
|
||||||
WriterStreamId: streamId,
|
WriterStreamId: streamId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start sending data to the RPC server
|
||||||
err = c.client.Call("Communicator.Download", &args, new(interface{}))
|
err = c.client.Call("Communicator.Download", &args, new(interface{}))
|
||||||
|
|
||||||
|
// Wait for the RPC server to finish receiving the data before we return
|
||||||
|
<-waitServer
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue