From 4997f546d28e2a02c6545be82194d42a90708ba8 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 27 Jan 2016 14:44:15 +0100 Subject: 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. --- ipc/ipc.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'ipc') 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) } -- cgit mrf-deployment