Skip to content

Failed to allocate directory watch

This is a possibly historical bug from last fall that may or may not be relevant, and I'm including it in this import of old issues from the other platform. Reasonable next steps would be to research the situation, then either implement permanent changes in Ansible or just close it out as no longer relevant.

https://blog.differentpla.net/blog/2022/12/14/failed-allocate-directory-watch/

While running apt-get upgrade, I was getting a Failed to allocate directory watch: Too many open files error.

It’s similar to this warning from Visual Studio Code, but this warning seems to be caused by having a large number of containers running.

You can see the current limits with sysctl fs.inotify. On Ubuntu, with the defaults, these are as follows:

fs.inotify.max_queued_events = 16384
fs.inotify.max_user_instances = 128
fs.inotify.max_user_watches = 65536

To fix the problem, I added /etc/sysctl.d/60-fs-inotify.conf, with the following contents:

fs.inotify.max_queued_events = 32768
fs.inotify.max_user_instances = 512
fs.inotify.max_user_watches = 524288

To reload the new settings, you need to run sudo sysctl --system.