nerdctl icon indicating copy to clipboard operation
nerdctl copied to clipboard

Add cleanup IO process after nerdctl stop

Open liuchangyan opened this issue 6 months ago • 8 comments

Fix #4315 In the ctr and CRI call paths of containerd, the remaining FIFO files (e.g., /run/containerd/fifo) are primarily cleaned up through the Delete interface of the task. However, in the nerdctl stop path, this interface is not invoked, so an explicit call to io.Close is required to clean them up.

liuchangyan avatar Jun 13 '25 10:06 liuchangyan

can we have a test please ?

fahedouch avatar Jun 13 '25 13:06 fahedouch

can we have a test please ?

Sure

liuchangyan avatar Jun 16 '25 02:06 liuchangyan

Hey @liuchangyan

Looks like the new tests are failing?

apostasie avatar Jul 23 '25 21:07 apostasie

I can help to create a ci for this bug.

ningmingxiao avatar Aug 05 '25 01:08 ningmingxiao

I can help to create a ci for this bug.

@ningmingxiao please go ahead

fahedouch avatar Aug 05 '25 08:08 fahedouch

I think we should mv io.close in waitContainerStop it will make sure container is really stopped. I create a pr https://github.com/containerd/nerdctl/pull/4443

func waitContainerStop(ctx context.Context, task containerd.Task, exitCh <-chan containerd.ExitStatus, id string) error {
	select {
	case <-ctx.Done():
		if err := ctx.Err(); err != nil {
			return fmt.Errorf("wait container %v: %w", id, err)
		}
		return nil
	case status := <-exitCh:
		// Cleanup the IO after a successful Stop
		if io := task.IO(); io != nil {
			if cerr := io.Close(); cerr != nil {
				log.G(ctx).Warnf("failed to close IO for container %s: %v", id, cerr)
			}
		}
		return status.Error()
	}
}

ningmingxiao avatar Aug 06 '25 04:08 ningmingxiao

Hi @liuchangyan,

What is the next step for this PR?

fahedouch avatar Aug 12 '25 17:08 fahedouch

Hi @liuchangyan,

What is the next step for this PR? I've removed my test sample since it looks like this PR4443 already covers that part. I think my original code still has value to keep. Should we merge both PRs together~ WDYT?

liuchangyan avatar Aug 13 '25 06:08 liuchangyan