loading...

Running VSCode On Linux: Hitting My Watcher Limit And What To Do About It

stephencweiss profile image Stephen Charles Weiss Originally published at stephencharlesweiss.com on ・2 min read

I have been working on a Linux VM more recently, and one particularly annoying thing about it (there are a lot of little quirks that are frustrating) was that VSCode couldn’t monitor for changes because it was out of watchers.

Watchers are part of the inotify Linux kernel subsystem1 that extend the filesystem to notice changes and report on those changes to applications listening for them.2

There are, however, a fixed number of watchers, and evidently, my machine’s default (8192) was insufficient to the task.

The fix was relatively straightforward: increase the number of watchers. The guard/listen repo has an informative post on the process. Quoting below3:

The technical details

Listen uses inotify by default on Linux to monitor directories for changes. It’s not uncommon to encounter a system limit on the number of files you can monitor. For example, Ubuntu Lucid’s (64bit) inotify limit is set to 8192.

You can get your current inotify file watch limit by executing:

$ cat /proc/sys/fs/inotify/max_user_watches

When this limit is not enough to monitor all files inside a directory, the limit must be increased for Listen to work properly.

You can set a new limit temporary with:

$ sudo sysctl fs.inotify.max_user_watches=524288

$ sudo sysctl -p

If you like to make your limit permanent, use:

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf

$ sudo sysctl -p

You may also need to pay attention to the values of max_queued_events and max_user_instances if Listen keeps on complaining

After making those changes, my VSCode was once again able to track my changes, which in turn, meant that the source control features were actually helpful and I didn’t have to use the terminal to see my diffs.

Footnotes

Posted on by:

stephencweiss profile

Stephen Charles Weiss

@stephencweiss

Engineer | Lover of dogs, books, and learning | Dos XX can be most interesting man in the world, I'm happy being the luckiest. | I write about what I learn @ code-comments.com

Discussion

markdown guide
 

Inotify is kinda awesome, really. The inotifywait cmd exposes an ignore pattern (like gitignore, rsync, etc). It would be GREAT if IDEs let us grab that, too! Preeeety sure, my limit is being reached because of the trillion files in my node_modules lol

 

Yea ist main suspect. But how would vs code know if we installed new module to get exports from it?

 

Could always fall-back to the universal polling mechanism (eg check ignored dirs every 3-ish seconds).

Alt, my Intellij has pre- and post-scripts that run after certain commands. Those could exec only after npm **.

This is purely theoretical, though 🤷‍♀️ (unless someone on here is building the IDEs)

 

trillion files in my node_modules

 w h a t

 

Rough estimate 😉

(But... Now I'm absolutely going to run a file count on my node_modules when I get back to the office)

Update:

❯ find . -type f | grep node_modules | wc -l
412140

But, to be fair: That's from a pretty large project with several microservice modules in it.

 

You can additionally exclude stuff. I have the below in my settings.json

"files.watcherExclude": {
    "**/.git/objects/**": true,
    "**/.git/subtree-cache/**": true,
    "**/node_modules/*/**": true,
    "**/package-lock.json": true,
    "**/yarn.lock": true,
    "**/dist/*/**": true,
    "**/vendor/*/**": true,
    "**/dist_electron/**": true,
},
 

Actually, having to increase the limit may mean that something is wrong with VSCode or rather one of its plugins. Such as that it monitors node_modules or something.

While increasing the limits helps to hack around the problem, it may actually backfire later. Would be useful to report it somewhere. I remember quite similar discussion about Parcel.

 

100% agree with this. At the time, however, I needed the hack and an ability to see my changes.

 

Thanks for sharing this no e hack I am planning to use a Linux VM soon for my Dev work, will use your hack

 

It's not a hack. That's day to day work on Linux. It's just another setting.

 

You can also add ignore folders and files in your settings file ignoring the virtual environment and folders such as .git will help.