|
276 | 276 | # Expect "no such unit" exit code.
|
277 | 277 | run -4 systemctl status $user "$SD_UNIT_NAME"
|
278 | 278 | }
|
| 279 | + |
| 280 | +@test "runc delete after create process killed" { |
| 281 | + # This test verifies that a container can be properly deleted |
| 282 | + # even if the runc create process was killed with SIGKILL |
| 283 | + |
| 284 | + [ $EUID -ne 0 ] && requires rootless_cgroup root cgroups_v1 |
| 285 | + set_cgroups_path |
| 286 | + |
| 287 | + # Add resource limits to slow down cgroup creation |
| 288 | + update_config '.linux.resources.memory.limit = 67108864' # 64MB |
| 289 | + update_config '.linux.resources.cpu.shares = 100' |
| 290 | + update_config '.linux.resources.cpu.quota = 10000' |
| 291 | + update_config '.linux.resources.cpu.period = 100000' |
| 292 | + |
| 293 | + # Add many device rules to further slow down cgroup creation |
| 294 | + update_config '.linux.resources.devices = []' |
| 295 | + for i in {1..300}; do |
| 296 | + update_config '.linux.resources.devices += [{"allow": true, "access": "rwm", "type": "c", "major": '"$i"', "minor": 0}]' |
| 297 | + done |
| 298 | + |
| 299 | + # Start runc create and kill it after 5ms with SIGKILL |
| 300 | + timeout --signal=SIGKILL --kill-after=0 0.05s "$RUNC" --debug ${RUNC_USE_SYSTEMD+--systemd-cgroup} --root "$ROOT/state" create --console-socket "$CONSOLE_SOCKET" test_create_killed || true |
| 301 | + |
| 302 | + # Wait briefly to ensure background processes complete |
| 303 | + sleep 1 |
| 304 | + |
| 305 | + # Check container state - should be in stopped state after SIGKILL |
| 306 | + runc state test_create_killed |
| 307 | + [ "$status" -eq 0 ] |
| 308 | + [[ "$output" == *"stopped"* || "$output" == *"paused"* ]] |
| 309 | + |
| 310 | + # Try to delete the container with force flag |
| 311 | + runc delete --force test_create_killed |
| 312 | + [ "$status" -eq 0 ] |
| 313 | + |
| 314 | + # Verify container no longer exists in the list |
| 315 | + runc list |
| 316 | + [[ "$output" != *"test_create_killed"* ]] |
| 317 | + |
| 318 | + # Check for any leftover runc init processes |
| 319 | + remaining_inits=$(pgrep -f "runc.*init.*test_create_killed" || true) |
| 320 | + [ -z "$remaining_inits" ] || fail "leftover runc init processes: $remaining_inits" |
| 321 | + |
| 322 | + # Check for leftover cgroups using standard pattern |
| 323 | + if [ -d "/sys/fs/cgroup" ]; then |
| 324 | + output=$(find /sys/fs/cgroup -name "*test_create_killed*" -type d 2>/dev/null || true) |
| 325 | + [ -z "$output" ] || fail "leftover cgroups found: $output" |
| 326 | + fi |
| 327 | +} |
0 commit comments