From 4b0c3249a94fb7bf01f7f58ca86c0ad694478b81 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Fri, 7 Jul 2017 15:56:47 +0200 Subject: [PATCH] Add a test for #872 This test that we don't panic if a container init process shim is SiGKILL'ed while having an exec attach to that container. Signed-off-by: Kenfe-Mickael Laventure --- integration-test/exec_test.go | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/integration-test/exec_test.go b/integration-test/exec_test.go index 23021e5e25..09567ae68e 100644 --- a/integration-test/exec_test.go +++ b/integration-test/exec_test.go @@ -3,7 +3,9 @@ package main import ( + "os/exec" "path/filepath" + "strings" "syscall" "time" @@ -394,3 +396,65 @@ func (cs *ContainerdSuite) TestBusyboxRestoreDeadExec(t *check.C) { t.Fatal("exec did not exit within 5 seconds") } } + +func (cs *ContainerdSuite) TestExecKillShimNoPanic(t *check.C) { + bundleName := "busybox-top" + if err := CreateBusyboxBundle(bundleName, []string{"top"}); err != nil { + t.Fatal(err) + } + + var ( + err error + initp *ContainerProcess + ) + + containerID := "top" + initp, err = cs.StartContainer(containerID, bundleName) + t.Assert(err, checker.Equals, nil) + + // Get the shim pid + b, err := exec.Command("pgrep", "containerd-shim").CombinedOutput() + t.Assert(err, checker.Equals, nil) + shimPid := strings.TrimSpace(string(b)) + t.Assert(string(shimPid), checker.Not(checker.Equals), "") + + execID := "top1" + _, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0) + t.Assert(err, checker.Equals, nil) + + for idx, evt := range []types.Event{ + { + Type: "start-container", + Id: containerID, + Status: 0, + Pid: "", + }, + { + Type: "start-process", + Id: containerID, + Status: 0, + Pid: execID, + }, + { + Type: "exit", + Id: containerID, + Status: 0xff, + Pid: execID, + }, + } { + ch := initp.GetEventsChannel() + e := <-ch + evt.Timestamp = e.Timestamp + t.Assert(*e, checker.Equals, evt) + if idx == 1 { + // Process Started, SIGKILL the container shim + err = exec.Command("kill", "-9", string(shimPid)).Run() + t.Assert(err, checker.Equals, nil) + } + } + + // Container should be dead + containers, err := cs.ListRunningContainers() + t.Assert(err, checker.Equals, nil) + t.Assert(len(containers), checker.Equals, 0) +}