aboutsummaryrefslogtreecommitdiffstats
path: root/vm/gvisor/gvisor.go
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2021-06-15 21:55:19 -0700
committerGitHub <noreply@github.com>2021-06-15 21:55:19 -0700
commitc06f97ad4b8a38e6396ff90f6084063f2303ad43 (patch)
treef334135cb0497dd55d8a8a319f8e94fd14163be4 /vm/gvisor/gvisor.go
parent990d3cbe39f4c5749bf753f60d6cc24b51b8de6b (diff)
vm/gvisor: stop instances properly (#2624)
Let's stop instances with "runsc kill" instead of killing sandbox processes. This will guarantee that ongoing rpc calls will not fail with unexpected errors. Reported-by: syzbot+084fca334720887441e7@syzkaller.appspotmail.com
Diffstat (limited to 'vm/gvisor/gvisor.go')
-rw-r--r--vm/gvisor/gvisor.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go
index 4365c22f9..31e3a10d5 100644
--- a/vm/gvisor/gvisor.go
+++ b/vm/gvisor/gvisor.go
@@ -316,8 +316,20 @@ func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command strin
signal(err)
return
}
- cmd.Process.Kill()
- cmd.Wait()
+ log.Logf(1, "stopping %s", inst.name)
+ w := make(chan bool)
+ go func() {
+ select {
+ case <-w:
+ return
+ case <-time.After(time.Minute):
+ cmd.Process.Kill()
+ }
+ }()
+ osutil.Run(time.Minute, inst.runscCmd("kill", inst.name, "9"))
+ err := cmd.Wait()
+ close(w)
+ log.Logf(1, "%s exited with %s", inst.name, err)
}()
return inst.merger.Output, errc, nil
}