Ubuntu 22.04下Buck2无法创建inotify监视器问题求助
Buck2构建时inotify限制报错(已调大上限仍无效)的排查方案
环境信息
- 系统:Ubuntu 22.04 (Jammy)
- Rust版本:nightly-2023-05-28(通过rustup安装)
- Buck2版本:
buck2 267ae15fcc862c9cd066152c8816e49f830d7715 <local>(cargo安装) - 生成的
.buckconfig配置:
[repositories] root = . prelude = prelude toolchains = toolchains none = none [repository_aliases] config = prelude fbcode = none fbsource = none buck = none [parser] target_platform_detector_spec = target:root//...->prelude//platforms:default
报错信息
$ buck2 build //... Error initializing DaemonStateData Caused by: 0: Error creating a FileWatcher for project root `<REDACTED PROJECT ROOT PATH>` 1: Creating notify file watcher 2: OS file watch limit reached. about ["<REDACTED FILE>"]
排查与解决方法
1. 调整inotify的其他限制参数
仅调大fs.inotify.max_user_watches可能不够,还有两个参数会影响:
- 修改单用户可创建的inotify实例数:
sudo sysctl -w fs.inotify.max_user_instances=1024 - 修改inotify事件队列的最大容量:
改完后直接重新运行构建命令测试。若要永久生效,将以下内容添加到sudo sysctl -w fs.inotify.max_queued_events=65536/etc/sysctl.conf,再执行sudo sysctl -p加载配置:fs.inotify.max_user_watches=524288 fs.inotify.max_user_instances=1024 fs.inotify.max_queued_events=65536
2. 处理报错中的特殊文件
报错指向的<REDACTED FILE>可能是符号链接、挂载点或特殊文件(如socket、设备文件),Buck2的监视器对这类文件可能存在处理问题:
- 若该文件非项目必需,在
.buckignore中添加规则排除它或其所在目录; - 若为符号链接,替换为实际文件路径,或检查是否存在循环引用。
3. 清理Buck2缓存与重启守护进程
旧的守护进程状态可能残留异常,执行以下命令重置:
buck2 kill rm -rf .buck2/ buck2 init buck2 build //...
4. 更新Buck2版本
你使用的提交版本(267ae15)较旧,可能存在文件监视器bug,尝试更新到最新版本:
cargo install --git https://github.com/facebook/buck2.git buck2
注意同步更新Rust nightly版本以保证兼容性。
5. 检查系统inotify资源占用
排查是否有其他进程占用大量inotify资源:
- 查看当前inotify使用情况:
sudo find /proc/*/fd -lname anon_inode:inotify | cut -d/ -f3 | xargs -I{} cat /proc/{}/fdinfo/$(ls -l /proc/{}/fd | grep anon_inode:inotify | awk '{print $9}') | grep -E '^inotify' | sort | uniq -c - 安装
inotify-tools后监视项目目录的inotify活动:
找到占用资源的进程,尝试关闭或调整其配置。sudo apt install inotify-tools inotifywatch -v -e access -e modify -t 60 /path/to/project/root
内容的提问来源于stack exchange,提问作者CodeMonkey
相关产品推荐
相关产品推荐

