Lxd eror message "Failed to stop device"

I am using custom volume “sharedvol” in default storage pool to share common data between two containers.
Every time when i stopping any one of two active containers lxd logs to journald:

lvl=eror msg="Failed to stop device" devName=sharedvol err="In use" instance=first_to_stop instanceType=container project=default

How to reproduce:

lxc storage volume create default sharedvol
lxc image copy images:archlinux local: --copy-aliases
lxc init local:archlinux cont1
lxc init local:archlinux cont2
lxc config device add cont1 sharedvol disk pool=default source=sharedvol path=/drop
lxc config device add cont2 sharedvol disk pool=default source=sharedvol path=/drop
lxc start cont1 cont2 
sleep 5 
lxc stop cont1 cont2 

journalctl -u lxd.service -n 1:

Sep 28 05:37:04 lxdsrv lxd[856]: t=2021-09-28T05:37:04+0300 lvl=eror msg="Failed to stop device" devName=sharedvol err="In use" instance=cont1 instanceType=container project=default

Do I understand correctly that this is just a misleading error message and not a real bug ?
Archlinux linux-lts=5.10.69 lxd=4.18 zfs=2.1.1

This is indeed only a misleading error message. When you call lxc stop cont1 cont2, LXD will stop cont1 first and try to unmount the device as well. However, since the device is still in use by cont2, it shows the error message.

It doesn’t happen with all storage drivers, but on zfs it does.

This should be an easy fix.

Thanks for confirming my conclusion :grinning:

We’ve reworked the fix in: