Skip to content

fix: clean up port-reserver.pid and the parent dir when the container…#4811

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
haytok:fix-cleanup-port-reserver-pid
Mar 30, 2026
Merged

fix: clean up port-reserver.pid and the parent dir when the container…#4811
AkihiroSuda merged 1 commit into
containerd:mainfrom
haytok:fix-cleanup-port-reserver-pid

Conversation

@haytok
Copy link
Copy Markdown
Member

@haytok haytok commented Mar 29, 2026

… is removed

In the current implementation, when a container is started with the -p option, a sleep infinity process is launched to reserve host ports.

The PID of this process is stored in
/run/nerdctl/<namespace>/<container ID>/port-reserver.pid.

When the container is removed, the following file and directory are expected to be cleaned up.

  • /run/nerdctl/<namespace>/<container ID>/port-reserver.pid
  • /run/nerdctl/<namespace>/<container ID>/

However, currently they are not removed as shown below:

$ sudo nerdctl run -d --name nginx -p 81:80 nginx
ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919

$ ls /run/nerdctl/default/ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919
port-reserver.pid

$ sudo nerdctl rm -f nginx
nginx

$ ls /run/nerdctl/default/ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919
port-reserver.pid

Therefore, this commit ensures that they are removed when the container is removed.

… is removed

In the current implementation, when a container is started with the -p
option, a `sleep infinity` process is launched to reserve host ports.

The PID of this process is stored in
`/run/nerdctl/<namespace>/<container ID>/port-reserver.pid`.

When the container is removed, the following file and directory are
expected to be cleaned up.

- /run/nerdctl/<namespace>/<container ID>/port-reserver.pid
- /run/nerdctl/<namespace>/<container ID>/

However, currently they are not removed as shown below:

```
$ sudo nerdctl run -d --name nginx -p 81:80 nginx
ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919

$ ls /run/nerdctl/default/ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919
port-reserver.pid

$ sudo nerdctl rm -f nginx
nginx

$ ls /run/nerdctl/default/ca1552d394cd8efcc5adcff9434deb4f3ead569d168f6e31bea1ae965db8b919
port-reserver.pid
```

Therefore, this commit ensures that they are removed when the container is
removed.

Signed-off-by: Hayato Kiwata <[email protected]>
@AkihiroSuda AkihiroSuda added this to the v2.3.0 milestone Mar 30, 2026
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit f5a981e into containerd:main Mar 30, 2026
76 of 84 checks passed
haytok added a commit to haytok/nerdctl that referenced this pull request Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants