`Too many open files` when running `find` on a disk mounted from host

Perhaps this is more of a LXC issue than an LXD one. Let me know if I should ask over there instead.

I’m not quite sure which of the many limits I might be brushing up against here, or why the open files are not being released.

All I’ve done is mount a disk from my host into a VM and mapped my host user ID to the guest user ID:

$ lxc version   
Client version: 5.21.2 LTS
Server version: 5.21.2 LTS
$ lxc config device add dev canonical disk source=/home/darndt/git/canonical/ path=/home/dev/canonical
$ lxc config set dev raw.idmap "both 1000 1002"

Then I’m trying to run this command (in the VM):

find "${HOME}/canonical" -name .git -prune

This works fine for a while, but eventually it fails with Too many open files.

After this, I can’t do anything on the mounted filesystem.

$ cd canonical
$ ls                             
ls: reading directory '.': Too many open files

I can still read/write outside of the mounted disk.

$ cd ..
$ ls
canonical  Downloads  snap  vm-share

What I’ve tried

(In the VM):

lsof didn’t indicate anything weird (to my eyes). I didn’t see large amounts of files remaining opened by the find command.

ulimit -n 2048
sudo sysctl -w fs.inotify.max_user_instances=2048

and adding

dev hard nofile 65536

to the /etc/security/limits.conf file without any luck.

Maybe the limit is coming from the host, but in any case I can’t figure out:

  1. How to increase this limit
  2. How to ensure these open files are eventually released so that this doesn’t become some sort of “maximum amount of files ever opened” limit.

I’m not very familiar with LXD/LXC, but even nudging me in the right direction would help a lot.