From c186ebb62a6005288d83feed0e43cca9f0577383 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Thu, 3 May 2018 21:08:38 -0700 Subject: Return error when child exits early PiperOrigin-RevId: 195365050 Change-Id: I8754dc7a3fc2975d422cae453762a455478a8e6a --- runsc/sandbox/sandbox.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'runsc/sandbox/sandbox.go') diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 954824ada..13bf5d800 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -560,19 +560,20 @@ func (s *Sandbox) createSandboxProcess(conf *boot.Config, binPath string, common // running, at which point the sandbox is in Created state. func (s *Sandbox) waitForCreated(timeout time.Duration) error { log.Debugf("Waiting for sandbox %q creation", s.ID) - tchan := time.After(timeout) - for { - select { - case <-tchan: - return fmt.Errorf("timed out waiting for sandbox control server") - default: - if c, err := client.ConnectTo(boot.ControlSocketAddr(s.ID)); err == nil { - // It's alive! - c.Close() - return nil - } + + ready := func() (bool, error) { + c, err := client.ConnectTo(boot.ControlSocketAddr(s.ID)) + if err != nil { + return false, nil } + // It's alive! + c.Close() + return true, nil } + if err := specutils.WaitForReady(s.Pid, timeout, ready); err != nil { + return fmt.Errorf("unexpected error waiting for sandbox %q, err: %v", s.ID, err) + } + return nil } // Wait waits for the containerized process to exit, and returns its WaitStatus. -- cgit v1.2.3