Commit 2ff1fabb authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/plugin: timeout when starting a plugin

parent c9c294f1
...@@ -25,18 +25,25 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) { ...@@ -25,18 +25,25 @@ func Command(cmd *exec.Cmd) (result packer.Command, err error) {
return return
} }
// Goroutine + channel to signal that the process exited
cmdExited := make(chan bool) cmdExited := make(chan bool)
go func() { go func() {
cmd.Wait() cmd.Wait()
cmdExited <- true cmdExited <- true
}() }()
// Timer for a timeout
cmdTimeout := time.After(1 * time.Minute)
var address string var address string
for done := false; !done; { for done := false; !done; {
select { select {
case <-cmdExited: case <-cmdExited:
err = errors.New("plugin exited before we could connect") err = errors.New("plugin exited before we could connect")
done = true done = true
case <- cmdTimeout:
err = errors.New("timeout while waiting for plugin to start")
done = true
default: default:
} }
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"testing" "testing"
) )
// TODO: Test timeout functionality
func TestCommand_NoExist(t *testing.T) { func TestCommand_NoExist(t *testing.T) {
assert := asserts.NewTestingAsserts(t, true) assert := asserts.NewTestingAsserts(t, true)
......
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