Skip to content

[JENKINS-73447] Do not fail the build when docker top is unavailable - #752

Open
AbdulMateenzwl wants to merge 1 commit into
jenkinsci:masterfrom
AbdulMateenzwl:JENKINS-73447-docker-top-unavailable
Open

[JENKINS-73447] Do not fail the build when docker top is unavailable#752
AbdulMateenzwl wants to merge 1 commit into
jenkinsci:masterfrom
AbdulMateenzwl:JENKINS-73447-docker-top-unavailable

Conversation

@AbdulMateenzwl

Copy link
Copy Markdown

Fixes #716 / JENKINS-73447.

Problem

After starting the container, WithContainerStep calls docker top to check that the
container is actually running the expected command (cat / cmd.exe) rather than
something from an ENTRYPOINT. docker top requires cgroups, so on rootless Docker and
rootless dind it fails outright:

Error response from daemon: runc did not terminate successfully: exit status 1:
unable to get all container pids: read /sys/fs/cgroup//cgroup.procs: operation not supported

The check is only ever advisory — when the process list does not contain the expected
command the step just logs an error and carries on — but an IOException from
listProcess propagated out of Execution.start() and failed the build, even though the
container was healthy.

Fix

Catch the IOException, log it at FINE, print a short note to the build log, and skip
the check. InterruptedException is deliberately not caught, so aborts still work.
listProcess is left throwing rather than returning an empty list, since an empty list
would trip the !ps.contains(command) branch and print the misleading "container started
but didn't run the expected command" message.

Testing

Added WithContainerStepTest.topFailureIsNotFatal, which installs a DockerTool whose
bin/docker is a wrapper that fails on top with the daemon error above and delegates
every other subcommand to the real docker — a stand-in for a cgroup-less daemon that
needs no refactoring of the step to inject a mock.

  • Without the fix the test fails with java.io.IOException: Failed to run top '<id>' and
    Finished: FAILURE, reproducing the reported bug.
  • With the fix the build succeeds, the body runs, and the log shows
    Could not verify the command running in the container: ....

mvn verify -Dtest=WithContainerStepTest passes locally against a real Linux daemon
(15 tests, 0 failures, SpotBugs clean). The new test calls assumeNotWindows(), since the
wrapper is a /bin/sh script, so it skips on the Windows CI leg.

Note

The reporter also suggested a system property to disable the process-list check outright.
I left that out — making the check non-fatal resolves the reported failure without adding
configuration surface — but I'm happy to add one if you'd prefer it.

`docker top` requires cgroups, so it fails on rootless Docker and rootless
dind even though the container is running normally. Its result is only a
diagnostic — a mismatch merely logs an error and the build continues — but
an `IOException` from `listProcess` propagated out of the step and aborted
the build.

Treat an unobtainable process list the same way: report it and skip the
check. `InterruptedException` still propagates.
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.

[JENKINS-73447] docker top returns error if Cgroups are not available (rootless docker, rootless dind)

1 participant