Skip to content

Bug: Delete() cannot clean up containers with invalid PID values (Pid <= 0) #778

Description

@Nachiket-Roy

During container creation, unikontainer.InitialSetup() persists the container state with:

Pid = -1
Status = creating

If container creation fails before unikontainer.Create() updates the PID, the container remains in this intermediate state.

Later, when attempting to clean up the failed container using:

urunc delete <container-id>

Delete() invokes isRunning(), which currently performs:

syscall.Kill(u.State.Pid, syscall.Signal(0))

without validating the PID value.

When Pid == -1, the call becomes:

syscall.Kill(-1, 0)

On Unix systems, kill(-1, sig) targets all processes that the caller has permission to signal. When running as a privileged user, this call succeeds, causing isRunning() to incorrectly return true.

As a result, Delete() refuses to remove the container and reports:

cannot delete running container: <container-id>

This leaves failed containers stuck in the creating state and prevents cleanup of the associated runtime state.

Steps to Reproduce

  1. Trigger a failure after unikontainer.InitialSetup() has completed but before unikontainer.Create() updates the PID.
  2. Observe that the persisted state contains:
{
  "status": "creating",
  "pid": -1
}
  1. Attempt to remove the failed container:
urunc delete <container-id>

Actual Behavior

Delete() reports that the container is still running:

cannot delete running container: <container-id>

and the runtime state cannot be cleaned up.

Expected Behavior

Containers with non-positive PIDs (Pid <= 0) should be considered not running, allowing cleanup to proceed.

Suggested Fix

Guard against invalid PID values in isRunning():

func (u *Unikontainer) isRunning() bool {
    if u.State.Pid <= 0 {
        return false
    }

    err := syscall.Kill(u.State.Pid, syscall.Signal(0))
    return err == nil
}

Additional Notes

InitialSetup() intentionally persists state before container creation completes, so failures during subsequent setup phases can legitimately leave containers with Pid = -1. Handling this case explicitly would allow these partially-created containers to be cleaned up correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreRelated to urunc's internalsbugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions