'restart: always' stops trying if mounted device is not found


Not sure if this is the expected behaviour, but picture this:

We have a compose file with a service which communicates with embedded devices via USB-serial converters:

version: "3.7"

        image: ourImage:latest
        restart: always
            - "/dev/ttyUSB0:/dev/ttyUSB0"
            - "/dev/ttyUSB2:/dev/ttyUSB1"
            - "/dev/ttyUSB3:/dev/ttyUSB2"
        tty: true

If an embedded device does not answer, or at least we do not receive bytes on the serial line, the service exits with error, and the restart:always policy restarts the service.
All this is fine, unless the USB-serial converter itself is removed/dropped, because the service exits fine, but the docker daemon fails to start the service, because the bound device is not available, and does not try again.

dockerd[1209]: time="2023-06-01T14:10:45.785906480+02:00" level=info msg="ignoring event" module=libcontainerd namespace=moby topic=/tasks/delete type="*events.TaskDelete"
dockerd[1209]: time="2023-06-01T14:10:46.225308867+02:00" level=error msg="86ab0f2b8c5d079c2ff76556fcbf0b9c085cb60f24bcac6739c139745062a2e9 cleanup: failed to delete container from containerd: no such container"
dockerd[1209]: time="2023-06-01T14:10:46.226666962+02:00" level=error msg="restartmanger wait error: error gathering device information while adding custom device \"/dev/ttyUSB0\": no such file or directory"

following this train of thought, this behaviour would mess up usecases, where in the event of a host (re)start the docker daemon would try to attach the still unavailable device, and prevent the start of the service

I am afraid it works as designed: if you specify devices to be mapped to a container, all of them must exist when the container starts.

If you feel this is an issue, then please open an issue in the Moby Github project: Issues · moby/moby · GitHub