"Error: Invalid PID" and others when starting an OCI container with `--console`

I’ve upgrade a dev server from 6.0-lts to 6.21; the host is Ubuntu 22.04 with kernel 5.15.0-170-generic.

I noticed something odd on testing the ‘hello-world’ OCI container:

nsrc@brian-kit:~$ incus launch oci-docker:hello-world
Launching the instance
Instance name is: harmless-humpback
nsrc@brian-kit:~$ incus list
...
| harmless-humpback | STOPPED |                      |      | CONTAINER (APP) | 0         |
nsrc@brian-kit:~$ incus start --console harmless-humpback

Error: Invalid PID '�'
nsrc@brian-kit:~$ incus start harmless-humpback
nsrc@brian-kit:~$ incus start harmless-humpback --console


Hello from Docker!
This message shows that your installation appears to be working correctly.
... etc

The problem reproduces perhaps one time in ten. Here with a new container, but started in same way:

nsrc@brian-kit:~$ incus start --console set-guppy


Hello from Docker!
<< snip >>
nsrc@brian-kit:~$ incus start --console set-guppy

Error: Invalid PID '�'

and occasionally a different error:

nsrc@brian-kit:~$ incus start --console set-guppy
To detach from the console, press: <ctrl>+a q
Error: Failed running forkconsole: "container is not running: \"set-guppy\""

Scripted reproducer, here with sleep 2 it only occasionally happens:

nsrc@brian-kit:~$ while true; do echo "."; incus start --console set-guppy >/dev/null; sleep 2; done
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Error: Invalid PID '�'
.
.
.
.
.
.
Error: Invalid PID '�'
.
.
.
.

It still happens even with sleep 10, so there’s plenty of time for the container to terminate:

nsrc@brian-kit:~$ for i in $(seq 1 30); do echo "."; incus start --console set-guppy >/dev/null || incus info --show-log set-guppy; sleep 10; done
.
.
Error: Invalid PID '�'
Error: Invalid PID '�'
.
.
.
.
.
.
.
.
.
Error: Invalid PID '�'
Error: Invalid PID '�'
.
.
.
.
.
Error: Invalid PID '�'
Error: Invalid PID '�'
.
.
.
.
Error: Invalid PID '�'
Error: Invalid PID '�'
.
.
.
.
Error: Invalid PID '�'
Error: Invalid PID '�'
.
.
^C

It’s possibly a race with hello-world terminating too quickly?

However with sleep 0.5 there’s a race in the opposite direction, with the container sometimes still running:

nsrc@brian-kit:~$ while true; do echo "."; incus start --console set-guppy >/dev/null; sleep 0.5; done
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
.
Error: The instance is already running
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
.
Error: The instance is already running
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
.
Error: The instance is already running
.
.
Error: The instance is already running
.
.
Error: The instance is already running
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
.
Error: The instance is already running
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
^C

This time with some logs:

nsrc@brian-kit:~$ while true; do echo "."; incus start --console set-guppy >/dev/null || incus info --show-log set-guppy; sleep 0.5; done
.
.
Error: The instance is already running
Error: Invalid PID '�'
.
.
Error: The instance is already running
Error: Invalid PID '�'
.
.
Error: The instance is already running
Error: Invalid PID '�'
.
.
Error: The instance is already running
Error: Invalid PID '�'
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
Error: Invalid PID '�'
.
Error: The instance is already running
Name: set-guppy
Description:
Status: STOPPED
Type: container (application)
Architecture: x86_64
Created: 2026/02/23 13:10 UTC
Last Used: 2026/02/23 13:23 UTC

Log:

lxc set-guppy 20260223132328.379 ERROR    apparmor - ../src/lxc/lsm/apparmor.c:apparmor_process_label_set_at:1175 - No such file or directory - Failed to write AppArmor profile "incus-set-guppy_</var/lib/incus>//&:incus-set-guppy_<var-lib-incus>:" to 17
lxc set-guppy 20260223132328.379 ERROR    apparmor - ../src/lxc/lsm/apparmor.c:apparmor_process_label_set:1221 - Invalid argument - Failed to change AppArmor profile to incus-set-guppy_</var/lib/incus>//&:incus-set-guppy_<var-lib-incus>:
lxc set-guppy 20260223132328.379 ERROR    sync - ../src/lxc/sync.c:sync_wait:34 - An error occurred in another process (expected sequence number 4)
lxc set-guppy 20260223132328.384 WARN     network - ../src/lxc/network.c:lxc_delete_network_priv:3674 - Failed to rename interface with index 0 from "eth0" to its initial name "veth53b35cb7"
lxc set-guppy 20260223132328.384 ERROR    lxccontainer - ../src/lxc/lxccontainer.c:wait_on_daemonized_start:832 - Received container state "ABORTING" instead of "RUNNING"
lxc set-guppy 20260223132328.384 ERROR    start - ../src/lxc/start.c:__lxc_start:2119 - Failed to spawn container "set-guppy"
lxc set-guppy 20260223132328.384 WARN     start - ../src/lxc/start.c:lxc_abort:1037 - No such process - Failed to send SIGKILL via pidfd 17 for process 371954
lxc 20260223132328.496 ERROR    af_unix - ../src/lxc/af_unix.c:lxc_abstract_unix_recv_fds_iov:218 - Connection reset by peer - Failed to receive response
lxc 20260223132328.496 ERROR    commands - ../src/lxc/commands.c:lxc_cmd_rsp_recv_fds:128 - Failed to receive file descriptors for command "get_init_pid"

.
.
Error: The instance is already running
Error: Invalid PID '�'
.
.
Error: Failed to run: /opt/incus/bin/incusd forkstart set-guppy /var/lib/incus/containers /run/incus/set-guppy/lxc.conf: exit status 1
Try `incus info --show-log set-guppy` for more info
Error: Invalid PID '�'
.
Error: The instance is already running
Name: set-guppy
Description:
Status: STOPPED
Type: container (application)
Architecture: x86_64
Created: 2026/02/23 13:10 UTC
Last Used: 2026/02/23 13:23 UTC

Log:

lxc set-guppy 20260223132332.449 ERROR    apparmor - ../src/lxc/lsm/apparmor.c:apparmor_process_label_set_at:1175 - No such file or directory - Failed to write AppArmor profile "incus-set-guppy_</var/lib/incus>//&:incus-set-guppy_<var-lib-incus>:" to 17
lxc set-guppy 20260223132332.450 ERROR    apparmor - ../src/lxc/lsm/apparmor.c:apparmor_process_label_set:1221 - Invalid argument - Failed to change AppArmor profile to incus-set-guppy_</var/lib/incus>//&:incus-set-guppy_<var-lib-incus>:
lxc set-guppy 20260223132332.450 ERROR    sync - ../src/lxc/sync.c:sync_wait:34 - An error occurred in another process (expected sequence number 4)
lxc set-guppy 20260223132332.454 WARN     network - ../src/lxc/network.c:lxc_delete_network_priv:3674 - Failed to rename interface with index 0 from "eth0" to its initial name "vethbc0e4f2c"
lxc set-guppy 20260223132332.454 ERROR    lxccontainer - ../src/lxc/lxccontainer.c:wait_on_daemonized_start:832 - Received container state "ABORTING" instead of "RUNNING"
lxc set-guppy 20260223132332.454 ERROR    start - ../src/lxc/start.c:__lxc_start:2119 - Failed to spawn container "set-guppy"
lxc set-guppy 20260223132332.454 WARN     start - ../src/lxc/start.c:lxc_abort:1037 - No such process - Failed to send SIGKILL via pidfd 17 for process 372493
lxc 20260223132332.585 ERROR    af_unix - ../src/lxc/af_unix.c:lxc_abstract_unix_recv_fds_iov:218 - Connection reset by peer - Failed to receive response
lxc 20260223132332.585 ERROR    commands - ../src/lxc/commands.c:lxc_cmd_rsp_recv_fds:128 - Failed to receive file descriptors for command "get_init_pid"

.
.
Error: The instance is already running
Error: Invalid PID '�'
^C

In summary, I think there are two issues here:

  1. Intermittent failures to start. This seems to rule out using incus to run OCI images entirely, unless it’s only related to console attachment - i.e. daemon services may be OK
  2. For scripting purposes: I want to be able to run a command in a container, in the foreground (so I can see its stdout/stderr), in such a way that when the command returns, the container is definitely finished and ready for immediate re-use. (Doing incus exec in a running container should be fine, but docker containers don’t necessarily run like that - they may be one-shot)