{"record":{"id":"552d3d8d590c7f10","repo":"jdx/mise","slug":"cannot-watch-the-system-s-watch-limit-is-reach","errorCode":null,"errorMessage":"cannot watch {}: the system's watch limit is reached (on Linux raise fs.inotify.max_user_watches)","messagePattern":"cannot watch (.+?): the system's watch limit is reached \\(on Linux raise fs\\.inotify\\.max_user_watches\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/watch/runtime.rs","lineNumber":1408,"sourceCode":"        if wanted.contains(anchor) {\n            current.push(anchor.clone());\n        } else if let Err(err) = debouncer.unwatch(&anchor.path) {\n            debug!(\"history watch: unwatch {}: {err}\", anchor.path.display());\n        }\n    }\n    for anchor in wanted {\n        if current.contains(anchor) {\n            continue;\n        }\n        let mode = match anchor.mode {\n            Mode::Recursive => RecursiveMode::Recursive,\n            Mode::Flat => RecursiveMode::NonRecursive,\n        };\n        match debouncer.watch(&anchor.path, mode) {\n            Ok(()) => current.push(anchor.clone()),\n            Err(err) if matches!(err.kind, notify::ErrorKind::MaxFilesWatch) => {\n                if current.is_empty() {\n                    bail!(\n                        \"cannot watch {}: the system's watch limit is reached (on Linux raise fs.inotify.max_user_watches)\",\n                        display_path(&anchor.path)\n                    );\n                }\n                let message = format!(\n                    \"cannot watch {}: the system's watch limit is reached; reconciliation still saves it (on Linux raise fs.inotify.max_user_watches)\",\n                    display_path(&anchor.path)\n                );\n                capture.health.watcher.degraded.push(message.clone());\n                capture.out.emit(\n                    \"degraded\",\n                    &message,\n                    json!({ \"path\": display_path(&anchor.path) }),\n                );\n            }\n            Err(err) => {\n                let message = format!(\n                    \"cannot watch {}: {err}; reconciliation still saves it\",","sourceCodeStart":1390,"sourceCodeEnd":1426,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/watch/runtime.rs#L1390-L1426","documentation":"The watch runtime installs a notify/debouncer watch for each anchor path. When the OS reports MaxFilesWatch and no watches are installed yet, it aborts: without a watch, changes would never be detected. On Linux this means the inotify per-user watch limit is exhausted.","triggerScenarios":"install (called by run/reinstall) calls debouncer.watch(anchor) which returns notify::ErrorKind::MaxFilesWatch while `current` is empty, i.e. the very first anchor cannot be watched.","commonSituations":"Large tracked sets, many other apps consuming inotify watches, containers with low fs.inotify.max_user_watches defaults, syncing huge directories like node_modules under a watched root.","solutions":["Raise the Linux inotify limit: `sudo sysctl fs.inotify.max_user_watches=524288` (persist in /etc/sysctl.conf or /etc/sysctl.d/).","Reduce the watched footprint: untrack or exclude very large directories.","On macOS/Windows, close apps consuming FSEvents/ReadDirectoryChangesW resources or reboot to clear leaked watches."],"exampleFix":"// before (default 8192 watches)\n// after\nsudo sysctl -w fs.inotify.max_user_watches=524288\necho 'fs.inotify.max_user_watches=524288' | sudo tee /etc/sysctl.d/99-inotify.conf && sudo sysctl --system","handlingStrategy":"fallback","validationCode":"// Linux: check available inotify watches\nlet max = std::fs::read_to_string(\"/proc/sys/fs/inotify/max_user_watches\").ok().and_then(|s| s.trim().parse::<u64>().ok());\nif max.is_some_and(|m| m < 524288) { eprintln!(\"consider raising fs.inotify.max_user_watches\"); }","typeGuard":null,"tryCatchPattern":"match install_watches() {\n  Err(e) if e.to_string().contains(\"watch limit\") => { raise_inotify_or_poll_fallback(); }\n  other => other?,\n}","preventionTips":["Raise fs.inotify.max_user_watches to 524288 on Linux dev machines.","Keep watch roots small; exclude node_modules and build output.","Audit watch consumers with `lsof | grep inotify` or inotify-tools."],"tags":["filesystem","inotify","watch-limit","linux"],"backgroundTag":"resource-limit-exceeded","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}