Skip to content

Commit 1a7f77f

Browse files
committed
fix: workaround podman stop/rm timeout in rootless mode with --pid host
In rootless mode with --pid host (distrobox default), podman stop/rm --force times out because "crun kill --all" fails when the container's cgroup-path is empty. Root cause: When using --pid host, the container shares the host's PID namespace and crun doesn't create a dedicated cgroup. The "crun kill --all" command relies on cgroup to find processes, but with empty cgroup-path, no processes are found and killed. Solution: Call "podman kill" before stop/rm, which uses "crun kill" (without --all flag) that sends signals directly to the container's init process PID, bypassing the cgroup lookup issue. Fixes: #1939 See also: chimera-linux/cports#1718 Signed-off-by: xz-dev <xiangzhedev@gmail.com>
1 parent 2995df5 commit 1a7f77f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

distrobox-rm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,28 @@ delete_container()
389389

390390
# Remove the container
391391
printf "Removing container...\n"
392+
# Workaround for podman rm --force timeout issue with --pid host in rootless mode.
393+
# See: https://github.com/chimera-linux/cports/issues/1718
394+
#
395+
# Root cause: In rootless mode with --pid host (distrobox default), the container's
396+
# cgroup-path is empty. When podman rm --force tries to stop the container, it uses
397+
# "crun kill --all" which relies on cgroup to find processes. With empty cgroup-path,
398+
# no processes are found and killed, causing the stop to timeout.
399+
#
400+
# Solution: Use "podman kill" first, which calls "crun kill" (without --all flag).
401+
# This sends the signal directly to the container's init process PID, bypassing
402+
# the cgroup lookup issue.
403+
#
404+
# Note: distrobox-rm does not call distrobox-stop (by design, it relies on
405+
# "podman rm --force" to handle stopping). A similar fix exists in distrobox-stop
406+
# for the "distrobox stop" command.
407+
if [ "${container_status}" = "running" ] && [ "${rootful}" -eq 0 ]; then
408+
case "${container_manager}" in
409+
*podman*)
410+
${container_manager} kill "${container_name}" > /dev/null 2>&1 || :
411+
;;
412+
esac
413+
fi
392414
# shellcheck disable=SC2086,SC2248
393415
${container_manager} rm ${force_flag} --volumes "${container_name}"
394416

distrobox-stop

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,20 @@ case "${response}" in
290290
y | Y | Yes | yes | YES)
291291
# Stop the container
292292
for container_name in ${container_name_list}; do
293-
${container_manager} stop "${container_name}"
293+
# Workaround for podman stop timeout issue with --pid host in rootless mode.
294+
# See: https://github.com/chimera-linux/cports/issues/1718
295+
# In rootless mode, podman stop uses "crun kill --all" which fails when
296+
# cgroup-path is empty (which happens with --pid host, the distrobox default).
297+
# Using "kill" first (which uses "crun kill" without --all) ensures the
298+
# container is terminated.
299+
if [ "${rootful}" -eq 0 ]; then
300+
case "${container_manager}" in
301+
*podman*)
302+
${container_manager} kill "${container_name}" 2> /dev/null || :
303+
;;
304+
esac
305+
fi
306+
${container_manager} stop "${container_name}" 2> /dev/null || :
294307
done
295308
;;
296309
n | N | No | no | NO)

0 commit comments

Comments
 (0)