summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFabricio Voznika <fvoznika@google.com>2018-06-28 13:22:12 -0700
committerShentubot <shentubot@google.com>2018-06-28 13:23:04 -0700
commitbb31a119035dd5266737b41456d967789693cf20 (patch)
treec7dd0c662562a0f4179836bc648ca24fd69204b9
parent1ceed49ba94c139be274fe5eaf367201ab0042a6 (diff)
Wait for sandbox process when waiting for root container
Closes #71 PiperOrigin-RevId: 202532762 Change-Id: I80a446ff638672ff08e6fd853cd77e28dd05d540
-rw-r--r--runsc/container/container.go2
-rw-r--r--runsc/sandbox/sandbox.go20
2 files changed, 21 insertions, 1 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go
index c7dc6ec10..b2ea78084 100644
--- a/runsc/container/container.go
+++ b/runsc/container/container.go
@@ -449,7 +449,7 @@ func (c *Container) Destroy() error {
// If we are the first container in the sandbox, take the sandbox down
// as well.
- if c.Sandbox != nil && c.Sandbox.ID == c.ID {
+ if c.Sandbox != nil && c.Sandbox.IsRootContainer(c.ID) {
if err := c.Sandbox.Destroy(); err != nil {
log.Warningf("Failed to destroy sandbox %q: %v", c.Sandbox.ID, err)
}
diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go
index ed2c40e57..e1e7b39d1 100644
--- a/runsc/sandbox/sandbox.go
+++ b/runsc/sandbox/sandbox.go
@@ -434,9 +434,29 @@ func (s *Sandbox) Wait(cid string) (syscall.WaitStatus, error) {
if err := conn.Call(boot.ContainerWait, &cid, &ws); err != nil {
return ws, fmt.Errorf("err waiting on container %q: %v", cid, err)
}
+
+ if s.IsRootContainer(cid) {
+ // If waiting for the root, give some time for the sandbox process to exit
+ // to prevent races with resources that might still be in use.
+ timeout := time.Now().Add(time.Second)
+ log.Debugf("Waiting for the sandbox process to exit")
+ for s.IsRunning() {
+ if time.Now().After(timeout) {
+ log.Debugf("Timeout waiting for sandbox process to exit")
+ break
+ }
+ time.Sleep(100 * time.Millisecond)
+ }
+ }
return ws, nil
}
+// IsRootContainer returns true if the specified container ID belongs to the
+// root container.
+func (s *Sandbox) IsRootContainer(cid string) bool {
+ return s.ID == cid
+}
+
// Stop stops the container in the sandbox.
func (s *Sandbox) Stop(cid string) error {
// TODO: This should stop the container with the given ID