summaryrefslogtreecommitdiffhomepage
path: root/runsc/container
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2021-07-22 15:37:37 -0700
committergVisor bot <gvisor-bot@google.com>2021-07-22 15:40:40 -0700
commit47f025461e6fdf8da99c780b17c2227696e83845 (patch)
tree1f65072ef1f3cbe4968f9cb1a02bb381ebd517a7 /runsc/container
parent8daeda207205f9c66083846e6ba231ab04e09163 (diff)
runsc: Wait child processes without timeouts
* First, we don't need to poll child processes. * Second, the 5 seconds timeout is too small if a host is overloaded. * Third, this can hide bugs in the code when we wait a process that isn't going to exit. PiperOrigin-RevId: 386337586
Diffstat (limited to 'runsc/container')
-rw-r--r--runsc/container/container.go41
1 files changed, 21 insertions, 20 deletions
diff --git a/runsc/container/container.go b/runsc/container/container.go
index 7f066905a..6a9a07afe 100644
--- a/runsc/container/container.go
+++ b/runsc/container/container.go
@@ -789,30 +789,31 @@ func (c *Container) stop() error {
}
func (c *Container) waitForStopped() error {
+ if c.GoferPid == 0 {
+ return nil
+ }
+
+ if c.IsSandboxRunning() {
+ if err := c.SignalContainer(unix.Signal(0), false); err == nil {
+ return fmt.Errorf("container is still running")
+ }
+ }
+
+ if c.goferIsChild {
+ // The gofer process is a child of the current process,
+ // so we can wait it and collect its zombie.
+ if _, err := unix.Wait4(int(c.GoferPid), nil, 0, nil); err != nil {
+ return fmt.Errorf("error waiting the gofer process: %v", err)
+ }
+ c.GoferPid = 0
+ return nil
+ }
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx)
op := func() error {
- if c.IsSandboxRunning() {
- if err := c.SignalContainer(unix.Signal(0), false); err == nil {
- return fmt.Errorf("container is still running")
- }
- }
- if c.GoferPid == 0 {
- return nil
- }
- if c.goferIsChild {
- // The gofer process is a child of the current process,
- // so we can wait it and collect its zombie.
- wpid, err := unix.Wait4(int(c.GoferPid), nil, unix.WNOHANG, nil)
- if err != nil {
- return fmt.Errorf("error waiting the gofer process: %v", err)
- }
- if wpid == 0 {
- return fmt.Errorf("gofer is still running")
- }
-
- } else if err := unix.Kill(c.GoferPid, 0); err == nil {
+ if err := unix.Kill(c.GoferPid, 0); err == nil {
return fmt.Errorf("gofer is still running")
}
c.GoferPid = 0