The config watcher opens millions of inotify watches under certain conditions
bug
**Describe the bug**
The quick explanation is that the `kitten` process will recursively create inotify watches for every single file inside the directories that `kitty.conf` or any included files are in. This results in over a million inotify watches on my system, exhausting the limits my kernel sets and prevents other applications from opening them.
The root cause of this is in `tools/watch/api.go` where the process gathers a list of parent directories and passes it onto `watch_dirs`, which then calls `fswatcher.WithPath` to recursively watch every directory that it's in.
In my case, I'm using NixOS and have a theme file in my `/nix/store` directory like so:
```
include /nix/store/hzsrj1w2rkcj6jqzgwwgwkby4pq0r50r-base16-custom-theme.conf
```
Which results in `kitten` creating a recursive `fswatcher` on my entire `/nix/store` directory. Hence the millions of inotify watches.
**To Reproduce**
Steps to reproduce the behavior:
1. Put a configuration file for your config to reference in a directory that contains a large number of files/subdirectories such as `/etc/kitty-config.conf`, `/nix/store/kitty-config.conf`, or even `/kitty-config.conf`.
2. Add an `include` statement in your `kitty.conf` to include this file.
3. Open up `kitty` and check the number of inotify watches it opens. Given a PID of `155266`, you can check this like so:
```
$ cat /proc/155266/fdinfo/* | grep 'inotify wd:' | wc -l
1473492
```
**Screenshots**
N/A
**Environment details**
```
kitty 0.47.1 created by Kovid Goyal
OS: NixOS, Linux 7.0.10-zen1 x86_64
```
**Additional context**
While this affected me due to using NixOS and having a theme file in `/nix/store` that gets included into my config, it technically affects any system that has these conditions. It is not necessarily NixOS specific.
关闭于 2026-06-02 10 条评论