diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-01-27 14:44:15 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-01-27 14:44:15 +0100 |
| commit | 4997f546d28e2a02c6545be82194d42a90708ba8 (patch) | |
| tree | c976551e746d8c8d1e905c4bda7ba3202fcabec1 /ipc | |
| parent | d1163f04801795d9c4f1fbf8c5611719cefe5b7e (diff) | |
ipc: give executor some time to startup
Namespace-based sandbox can take some time to setup.
In particular, lots of parallel executors block on net
namespace creation.
Diffstat (limited to 'ipc')
| -rw-r--r-- | ipc/ipc.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ipc/ipc.go b/ipc/ipc.go index b7c647478..0f8cac7ee 100644 --- a/ipc/ipc.go +++ b/ipc/ipc.go @@ -352,6 +352,10 @@ func makeCommand(bin []string, timeout time.Duration, flags uint64, inFile *os.F return nil, fmt.Errorf("failed to start executor binary: %v", err) } c.cmd = cmd + if err := c.waitServing(); err != nil { + return nil, err + } + tmp := c c = nil // disable defer above return tmp, nil @@ -375,6 +379,24 @@ func (c *command) close() { } } +// Wait for executor to start serving (sandbox setup can take significant time). +func (c *command) waitServing() error { + read := make(chan error, 1) + go func() { + var buf [1]byte + _, err := c.inrp.Read(buf[:]) + read <- err + }() + timeout := time.NewTimer(time.Minute) + select { + case err := <-read: + timeout.Stop() + return err + case <-timeout.C: + return fmt.Errorf("executor is not serving") + } +} + func (c *command) kill() { syscall.Kill(c.cmd.Process.Pid, syscall.SIGKILL) } |
