Skip to content

Commit caea35f

Browse files
committed
test:add ci for cleanup fifos
Signed-off-by: ningmingxiao <[email protected]>
1 parent bd89fee commit caea35f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cmd/nerdctl/container/container_stop_linux_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,23 @@ func TestStopWithTimeout(t *testing.T) {
199199
// The container should get the SIGKILL before the 10s default timeout
200200
assert.Assert(t, elapsed < 10*time.Second, "Container did not respect --timeout flag")
201201
}
202+
func TestStopCleanupFIFOs(t *testing.T) {
203+
if rootlessutil.IsRootless() {
204+
t.Skip("/run/containerd/fifo/ doesn't exist on rootless")
205+
}
206+
testutil.DockerIncompatible(t)
207+
base := testutil.NewBase(t)
208+
testContainerName := testutil.Identifier(t)
209+
oldNumFifos, err := countFIFOFiles("/run/containerd/fifo/")
210+
assert.NilError(t, err)
211+
// Stop the container after 2 seconds
212+
go func() {
213+
time.Sleep(2 * time.Second)
214+
base.Cmd("stop", testContainerName).AssertOK()
215+
newNumFifos, err := countFIFOFiles("/run/containerd/fifo/")
216+
assert.NilError(t, err)
217+
assert.Equal(t, oldNumFifos, newNumFifos)
218+
}()
219+
// Start a container that is automatically removed after it exits
220+
base.Cmd("run", "--rm", "--name", testContainerName, testutil.NginxAlpineImage).AssertOK()
221+
}

pkg/containerutil/containerutil.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ func Stop(ctx context.Context, container containerd.Container, timeout *time.Dur
376376
return err
377377
}
378378

379+
// Cleanup the IO after a successful Stop
380+
io := task.IO()
381+
if io != nil {
382+
defer func() {
383+
if cerr := io.Close(); cerr != nil {
384+
log.G(ctx).Warnf("failed to close IO for container %s: %v", container.ID(), cerr)
385+
}
386+
}()
387+
}
388+
379389
status, err := task.Status(ctx)
380390
if err != nil {
381391
return err

0 commit comments

Comments
 (0)