fix(healthcheck): release exec process resources after probe#4911
Open
haytok wants to merge 1 commit into
Open
fix(healthcheck): release exec process resources after probe#4911haytok wants to merge 1 commit into
haytok wants to merge 1 commit into
Conversation
Each invocation of a health check runs the user-defined command inside
the container via containerd's `task.Exec()` API.
We can verify this in the `probeHealthCheck` section of the healthcheck
package as follows:
```golang
func probeHealthCheck(ctx context.Context, task containerd.Task, hc *Healthcheck, processSpec *specs.Process) (*HealthcheckResult, error) {
...
process, err := task.Exec(ctx, execID, processSpec, cio.NewCreator(
cio.WithStreams(nil, outputBuf, outputBuf),
))
...
if err := process.Start(ctx); err != nil {
log.G(ctx).Debugf("failed to start health check: %v", err)
return nil, fmt.Errorf("start error: %w", err)
}
exitStatusC, err := process.Wait(ctx)
if err != nil {
return nil, fmt.Errorf("failed to wait for health check: %w", err)
}
```
However, the current implementation does not release the resources
allocated during the health check once the check is complete.
As a result, for example, pipes that should normally be deleted are not
removed and continue to accumulate over time.
We can verify this behavior using the following command:
```bash
$ sudo nerdctl run -d --name=health --health-cmd="curl -f http://localhost" --health-interval=1s --health-timeout=1m0s --health-retries=3 --health-start-period=2s nginx:alpine
f2fdd8346a546bc6ef446980efdce1132a436fa63bd64a8ce6756c6197e7ec3f
$ TASK_PID=$(sudo nerdctl inspect health --format '{{.State.Pid}}')
$ SHIM_PID=$(ps -o ppid= -p $TASK_PID | tr -d ' ')
$ sudo ls -la /proc/$SHIM_PID/fd | grep pipe | head -3
lr-x------ 1 root root 64 May 17 20:51 100 -> pipe:[1093131]
lr-x------ 1 root root 64 May 17 20:52 101 -> pipe:[1092248]
lr-x------ 1 root root 64 May 17 20:52 102 -> pipe:[1092228]
$ sudo ls -la /proc/$SHIM_PID/fd | grep pipe | wc -l
16
$ sleep 10
$ sudo ls -la /proc/$SHIM_PID/fd | grep pipe | wc -l
26
```
So, this change adds a deferred `process.Delete()` after `task.Exec()` so that
the allocated resources are released when the exec process completes.
Signed-off-by: Hayato Kiwata <dev@haytok.jp>
sathiraumesh
suggested changes
May 18, 2026
sathiraumesh
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each invocation of a health check runs the user-defined command inside the container via containerd's
task.Exec()API.We can verify this in the
probeHealthChecksection of the healthcheck package as follows:However, the current implementation does not release the resources allocated during the health check once the check is complete.
As a result, for example, pipes that should normally be deleted are not removed and continue to accumulate over time.
We can verify this behavior using the following command:
So, this change adds a deferred
process.Delete()aftertask.Exec()so that the allocated resources are released when the exec process completes.