watchexec: Too many open files (os error 24) (again)

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 21.10
Release:        21.10
Codename:       impish

watchexec --version
watchexec 1.18.6

The command

watchexec -p --exts md,css -f '*/justfile' -f '*/.env' "just run"

still fails with

Error: watchexec::critical::elevated_runtime

  × elevated: Native watcher failed to instantiate: Too many open files (os error 24)
  ├─▶ Native watcher failed to instantiate: Too many open files (os error 24)
  ╰─▶ Too many open files (os error 24)

I wrote a quick diagnostic shell function that displays values for all related parameters (to my knowledge). I cannot find any possible explanation for why error 24 would be raised.

See for yourself:

fs_ressources_diag(){
    file_nr="$(awk '{print $1}' /proc/sys/fs/file-nr)"
    file_max="$(cat /proc/sys/fs/file-max)"
    h_ulimit="$(ulimit -Hn)"
    s_ulimit="$(ulimit -Sn)"
    inotify_max="$(cat /proc/sys/fs/inotify/max_user_watches)"
    cat <<EOF
System
    Number of open file handles: current=${file_nr} / max=${file_max}
Current process
    Maximum number of open file handles: hard=${h_ulimit} / soft=${s_ulimit}
Inotify
    fs.inotify.max_user_watches=${inotify_max}
EOF
}

fs_ressources_diag

System
    Number of open file handles: current=59180 / max=9223372036854775807
Current process
    Maximum number of open file handles: hard=1000000 / soft=1000000
Inotify
    fs.inotify.max_user_watches=1048576

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Found the culprit. The value of fs.inotify.max_user_instances was too low

Good find! I’ll add it to the help text as well as to the online documentation page which the error links to.

I think such an output would make life easier for watchexec’s users

It’s a bit limited to linux, and I don’t think including it as part of the cli would be the way, but building it as a separate tool that’s officially recommended for debugging watchexec issues (as well as other inotify-based tools!) would work well.

Found the culprit. The value of fs.inotify.max_user_instances was too low:

cat /proc/sys/fs/inotify/max_user_instances 
128
echo 256 | sudo tee /proc/sys/fs/inotify/max_user_instances
256
watchexec -w . --exts txt "echo ok"
ok

Also, does polling mode work?

In the same test directory as above:

watchexec -w . --exts txt --force-poll 150 "echo ok"
ok