-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux: implement a different watcher that does not require file handles per file in the workspace folder #45295
Comments
I just got this myself when opening a new folder in a window I had open. I clicked the button to see instructions, but nothing happened. VS Code version: 1.21.0 |
@GregoryLundberg @Stigjb the button should open a browser pointing to these instructions: https://code.visualstudio.com/docs/setup/linux#_error-enospc Did no browser open? |
It opened for me, but there is nothing there about running out of file handles, only about running out of disk space. Neither are true and I clicked to never see the notification again because it's a obviously a false-positive. |
@GregoryLundberg so you did not see https://code.visualstudio.com/docs/setup/linux#_error-enospc open in your browser? What page did open for you then? |
YES the browser opened. YES it showed that page. NO it does not speak about how to fix your program bug claiming it ran out of FILE handles. ENOSPC means out of space on the drive. I am not. The notification says it's out of FILE handles. It is not. I increased the limit from 1024 to 4096 to no effect. As I read the web page, it's about running out of some other sort of handles so it's not about FILE handles and does not apply to the notification. I clicked to ignore the error because it's obviously a false positive since there are plenty of file handles. I thought perhaps I could re-enable it to post a screen shot but I don't see a settings option for it. Where did you hide the options? There doesn't look to be anything under File|Preferences|Settings or <gear>|Settings. |
OK I read what that page says and half a million file "watches" won't do. If it's really a problem you'll either need to clean up your code or document that VS Code is only for small to moderate sized projects. My project tree has far more than half-a-million files, and there is no reason for you to "watch" every single one of them, which is, I guess, what that error is about. I guess your notification meant "out of file-watch handles" and someone omitted the qualifier. Perhaps the breakage is you're trying to watch everything when you really only need to watch files which are actually open in the editor (which, at the time the notification appeared was one: your release notes, which automatically appears). |
The browser did not open for me. |
@GregoryLundberg we should probably update the documentation so that its clear that the ENOSPC error is in fact the same error for running out of file handles. Currently we have no other way than requiring you to change the limit in your config file to make it work. @Stigjb that is weird. if you have a http link in the editor and you ctrl+click it, does it also not open any browser? |
You're serious? What in the world do you need more than 4096 open files for? If you're trying to open every file in my project, I doubt I can set the limit that high. I suppose I could try bumping to 32K. It won't come close to opening every file, but it sounds sufficiently insane. Not that I can tell if it has an effect because I don't know how to re-enable the notification, so it seems sort of pointless. |
@GregoryLundberg two things we can try. First, we have a setting |
How do I re-enable the notification? Not much point in testing if I can't see the results. |
@GregoryLundberg that notification shows up per workspace, so if you just rename the folder you open it should show again. |
Sorry. No can do. |
@GregoryLundberg no problemo, an easier way of doing it: from the command line run |
Too bad there's no way to re-enable the notifications properly. Probably should open a new issue for that. Seems like a pretty serious design flaw. Using a forced directory, I see the notification, again. Are you sure the message is not incorrect and it's not about file handles at all? The documentation says file WATCH handles. Maybe the documentation is correct and the notification message is wrong? Well, whatever is wrong, it seems the correct option is to ignore it. You don't seem to need whatever you're complaining about. |
For resetting the notification preference, we have #24815 The message is correct and it is about file handles. The file watcher we have needs 1 file handle per file on Linux to support the watching (unfortunately). When the list of file handles exceeds the OS limit, VS Code will still function but some file events will not be recorded and be missing. E.g. if you delete a file in the Linux explorer, you will not see that file go away from the VS Code explorer. Another thing to try is to configure Is there a particular large folder that you hide, e.g. some |
So problem is simply bad design on your part. Since you use one file handle per file, you have a limit on project size of 4096 files. You should clearly document, therefore, that VS Code is only usable for small projects. Since my project has over 8000 files just for the primary C++ headers and footers, there is no way for you to work without error. I've not used inotify(7) but would have assumed it was more efficient than you're implying. |
@GregoryLundberg yeah it is bad design on our part, we should only watch what is actually needed by having an API where you opt-in to specific paths that should be watched as opposed to watching everything. I do not think there is a way to watch files on Linux recursively without requiring a file-handle per file in the workspace. On Windows and macOS however, file watchers do NOT require any file handles per file. So this issue is actually only showing up on Linux unfortunately. |
According to the man page, one file-watcher handle per directory should do for all files and directories within that directory. It does not say recursive, so, I'd assume (not tested) that creating, renaming or deleting a directory would get a notification event on the directory where it appears. As I said, though, I've never actually used inotify and am not sure I could throw together a test case. |
I'm also noticing this. I'm much more curious to hear why this is suddenly a new problem. Why did 1.20 not complain about file handles? Was it just silently ignored? I've used Code on workspaces with 10,000+ files before with no obvious issues or loss in functionality. |
@sagebind yes it was silently ignored and you would see no file watching support without actually understanding what is going on. |
Any update on this bug? |
I run into watcher issues a few weeks ago, seemed exactly like the problem described in #50417 which led me to this issue and its references; all of which fit the pattern with Here are 2 observations which I didn't see mention anywhere, although behind the scenes (just a guess, I'm not familiar with VS Code code base) they "feel" like related to multi-root workspace (#40898)
If those are expected behaviors, then you can skip the rest of the post, which is reproduction steps. Test objects are 2 clean projects (
Max file watchers count is the default one, and each project, without First case
Second case Open When working in single directory and files within, the exclusion seems to be working as expected (at least I couldn't find a minimal reproduction; same when paying attention in real life projects). Also, didn't notice above issues (out of watchers when trying to run app in dev mode) with other editors. I hope above helps at least a bit. VS Code info at the time of writing:
|
Also experiencing this on Ubuntu 18.04. |
To help with diagnosing this issue, I came up with this script that prints files being watched in a workspace or folder (remember to change the #!/usr/bin/env zsh
# this script prints a series of paragraphs:
# - each paragraph corresponds to an inotify instance
# - the first line prints the process owning that inotify instance
# - each line in the rest of the paragraph corresponds to a file being
# watched by the inotify instance
workspace=${HOME}/src/writerite/frontend-react
# create an associative array of inodes to their paths in the workspace
typeset -A inode_map
# list all the files in the workspace, then pass all the paths to ls to obtain
# their corresponding inodes, then sort these lines to uniquify the inodes in case
# duplicate hard links are present; then for each line
find "$workspace" -exec ls -di {} + | sort -nu -k1,1 | while read line
do
# split it into words by the word-separator, then initialize an array with these words
line_arr=(${=line})
# the first word is the inode, so assign it as the key, whereas the other words form the path
inode_map[$line_arr[1]]="$line_arr[2,-1]"
done
# for each inotify instance (found through iterating through each
# file descriptor opened by each process and seeing if it is an
# inotify file descriptor)
find /proc/*/fd/* -type l -lname 'anon_inode:inotify' 2> /dev/null |
while read line
do
# print the process name for later printing
process=$(sed -e 's@^/proc/\([[:digit:]]*\)/fd/[[:digit:]]*@\1@' <<< $line)
cat "/proc/${process}/cmdline"
echo
# for each path to the file descriptor
echo $line |
# modify it to a path to the file descriptor info file
sed -e 's@/fd/@/fdinfo/@' |
# and print its contents
xargs cat |
# filter for the lines containing information about the files
# watched in this instance (one line corresponds to one watch)
grep inotify |
# extract the hex-encoded inode of the file being watched
sed -e 's/^.*ino:\([[:xdigit:]]*\) .*$/0x\1/' |
while read line
do
# if the inode corresponds to a file in the workspace
if [[ $inode_map[$((line))] ]]
then
# echo the file path
echo "$inode_map[$((line))]"
fi
done
echo
done |
Related to this issue, my script also catches that VSCode's TypeScript support watches |
work for me! lifesaver |
Was the experimental watcher activated by |
It doesn't work. I tried |
As this still cause lots of issues for us (large repo) after setting kernel limits to max I wonder if the Linux possibilities has been investigated properly. I'm no expert at inotify() and I agree that there is probably no recursive flag like bWatchSubtree like for Windows. But to me it looks like there could be a workaround by watching directories instead. From "man inotify": Using this would probably mean some framework where when you want to add a file watch you would instead add an entry into the parent directory watcher that will handle forwarding for file events. But to me it sounds doable. (Not knowing vscode internals at all.) Seems like there are existing wrappers for making inotify recursive, for example: On a related note; is there maybe already some method to get vscode to refresh directory contents whenever you expand a directory? This would be very useful to not have to remember to hit the refresh button for those folders that we are excluding from being watched. When a file is renamed or similar. |
From
VSCode has 2 bits of code that mention
The Watcher creation is handled in
The setup code passes a list of folders to the watcher.
What What also doesn't seem to be the case is that (correct me if I'm wrong here devs... ) My suggestion for an improvement would be to put a callback in * This assumption is based entirely on it lacking the string "overflow" in it's code tree. If |
We will be shipping a new file watcher (#132483) starting in insiders tomorrow that allows to exclude folders natively from watching via the I do not see a solution on Linux to watch a folder recursively without requiring a file handle per folder in the tree, so I will go ahead and close this issue. Recursive watching is a requirement of VS Code that we cannot lift because extensions rely on file events from any file within the opened workspace. |
Steps to Reproduce:
Does this issue occur when all extensions are disabled?: Yes
Dialog message indicates the web page has help. It does not.
Bumped (soft) open file limit from 1024 to 4096: no help.
The text was updated successfully, but these errors were encountered: