`lxc ls` on an LXD cluster is very slow

Hi everyone!

I’m running into an odd issue right now; running lxc ls takes upwards of 30 seconds to execute on our LXD cluster. This is interfering with a JupyterHub instance (which spawns LXD containers) of ours which times out and fails when this happens, so I’d love to get it fixed, but I’m a loss as to what the problem is.

Interestingly, lxc ls --fast doesn’t have this problem, and I’ve tracked the issue down to the difference between the two commands; whether recursion=2 (for lxc ls) or recursion=1 (for lxc ls --fast) is given as parameters to the /1.0/instances GET request.

$ time curl --silent --unix-socket /var/snap/lxd/common/lxd/unix.socket s/1.0/instances?recursion=1 > /dev/null
real    0m0.400s
user    0m0.015s
sys     0m0.006s
$ time curl --silent --unix-socket /var/snap/lxd/common/lxd/unix.socket s/1.0/instances?recursion=2 > /dev/null
real    0m19.213s
user    0m0.012s
sys     0m0.009s

Does anybody have any ideas as to why this happens?

Here’s the output of lxc info: https://gist.github.com/mt-caret/e766ada57e24496a7ffe7962de098dae

Rebooting the machine seems to have fixed the problem, weird!