X Tutup
Skip to content

Commit 31a710c

Browse files
committed
fix: should not send 137 code event if cmd is notfound
ShimV2 has shim.Delete command to cleanup task's temporary resource, like bundle folder. Since the shim server exits and no persistent store is for task's exit code, the result of shim.Delete is always 137 exit code, like the task has been killed. And the result of shim.Delete can be used as task event only when the shim server is killed somehow after container is running. Therefore, dockerd, which watches task exit event to update status of container, can report correct status. Back to the issue containerd#6429, the container is not running because the entrypoint is not found. Based on this design, we should not send 137 exitcode event to subscriber. This commit is aimed to remove shim instance first and then the `cleanupAfterDeadShim` should not send event. Similar Issue: containerd#4769 Fix containerd#6429 Signed-off-by: Wei Fu <fuweid89@gmail.com>
1 parent ad77111 commit 31a710c

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

integration/client/container_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,67 @@ func TestRegressionIssue4769(t *testing.T) {
19461946
}
19471947
}
19481948

1949+
// TestRegressionIssue6429 should not send exit event out if command is not found.
1950+
//
1951+
// Issue: https://github.com/containerd/containerd/issues/6429.
1952+
func TestRegressionIssue6429(t *testing.T) {
1953+
t.Parallel()
1954+
1955+
if runtime.GOOS == "windows" {
1956+
t.Skip("Test relies on runc")
1957+
}
1958+
1959+
client, err := newClient(t, address)
1960+
if err != nil {
1961+
t.Fatal(err)
1962+
}
1963+
defer client.Close()
1964+
1965+
// use unique namespace to get unique task events
1966+
id := t.Name()
1967+
ns := fmt.Sprintf("%s-%s", testNamespace, id)
1968+
1969+
ctx, cancel := context.WithCancel(context.Background())
1970+
defer cancel()
1971+
1972+
ctx = namespaces.WithNamespace(ctx, ns)
1973+
ctx = logtest.WithT(ctx, t)
1974+
1975+
image, err := client.Pull(ctx, testImage, WithPullUnpack)
1976+
if err != nil {
1977+
t.Fatal(err)
1978+
}
1979+
defer client.ImageService().Delete(ctx, testImage, images.SynchronousDelete())
1980+
1981+
container, err := client.NewContainer(ctx, id,
1982+
WithNewSnapshot(id, image),
1983+
WithNewSpec(oci.WithImageConfig(image), withProcessArgs("notfound404")),
1984+
WithRuntime(client.Runtime(), nil),
1985+
)
1986+
if err != nil {
1987+
t.Fatal(err)
1988+
}
1989+
defer container.Delete(ctx, WithSnapshotCleanup)
1990+
1991+
eventStream, errC := client.EventService().Subscribe(ctx, "namespace=="+ns+",topic~=|^/tasks/exit|")
1992+
1993+
if _, err := container.NewTask(ctx, empty()); err == nil {
1994+
t.Fatalf("expected error but got nil")
1995+
}
1996+
1997+
var timeout = 10 * time.Second
1998+
1999+
// start to check events
2000+
select {
2001+
case et := <-eventStream:
2002+
t.Fatal(fmt.Errorf("unexpected task exit event: %+v", et))
2003+
case err := <-errC:
2004+
t.Fatal(fmt.Errorf("unexpected error from event service: %w", err))
2005+
2006+
case <-time.After(timeout):
2007+
}
2008+
}
2009+
19492010
func TestDaemonRestart(t *testing.T) {
19502011
client, err := newClient(t, address)
19512012
if err != nil {

runtime/v2/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ func (m *TaskManager) Create(ctx context.Context, taskID string, opts runtime.Cr
375375
shim := process.(*shimTask)
376376
t, err := shim.Create(ctx, opts)
377377
if err != nil {
378+
// NOTE: ctx contains required namespace information.
379+
m.manager.shims.Delete(ctx, taskID)
380+
378381
dctx, cancel := timeout.WithContext(context.Background(), cleanupTimeout)
379382
defer cancel()
380383

381-
_, errShim := shim.delete(dctx, func(ctx context.Context, id string) {
382-
m.manager.shims.Delete(ctx, id)
383-
})
384-
384+
_, errShim := shim.delete(dctx, func(context.Context, string) {})
385385
if errShim != nil {
386386
if errdefs.IsDeadlineExceeded(errShim) {
387387
dctx, cancel = timeout.WithContext(context.Background(), cleanupTimeout)

0 commit comments

Comments
 (0)
X Tutup