-
Notifications
You must be signed in to change notification settings - Fork 235
Using Find References on Linux causes Editor Services to crash with "too many open files" #612
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
Comments
This + a |
Seems like any sort of "workspace level" processing needs to be accompanied by a setting like |
Yep, definitely. Maybe a 'foldersToExclude' configuration that gets passed along to PSES would be useful to reduce the weight of commonly large folders. It'd be nice if we could use file pattern globbing for more specific matching. @rkeithhill do you know of any APIs we could borrow from PowerShell to do file/path matching? |
|
From what I can tell, it looks like the issue happens here: This looks like it's an issue with .NET Core not cleaning up after itself since all we want are files with
Also, the call to |
Wait I might have figured it out... The Directory.EnumerateFiles(
folderPath,
pattern,
SearchOption.AllDirectories)); This call doesn't crash in a folder that crashed previously! |
The full function basically looks like this: private IEnumerable<string> RecursivelyEnumerateFiles(string folderPath)
{
var foundFiles = Enumerable.Empty<string>();
var patterns = new string[] { @"*.ps1", @"*.psm1", @"*.psd1" };
foreach (var pattern in patterns)
{
try
{
foundFiles =
foundFiles.Concat(
Directory.EnumerateFiles(
folderPath,
pattern,
SearchOption.AllDirectories));
}
catch (DirectoryNotFoundException e)
{
this.logger.WriteException(
$"Could not enumerate files in the path '{folderPath}' due to it being an invalid path",
e);
}
catch (PathTooLongException e)
{
this.logger.WriteException(
$"Could not enumerate files in the path '{folderPath}' due to the path being too long",
e);
}
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
{
this.logger.WriteException(
$"Could not enumerate files in the path '{folderPath}' due to the path not being accessible",
e);
}
}
return foundFiles;
} |
I recommend you also catch |
We were using this approach in the past, but the problem is that it stops enumerating on the first exception that it finds and there's no way to resume it: 0788a3e#diff-7500716c7e03a30040a8f1664f42be23 We broke this out into our own loop so that we can catch the exceptions more granularly without interrupting the scan. |
Makes sense. So you don't think this is the right solution? |
Yeah, because if the first file/folder we look at throws an exception, none of the other files will be scanned, leaving the user to wonder why Find References, etc doesn't work. |
I get that... but if we use SearchOptions on Linux and Mac, that at least prevents a crash. And looking at our exceptions, how often do they happen?
The case I'm trying to make is that, I'd rather see no results than a crash on linux/mac. Please correct me if I have something wrong or let me know what your thoughts are. Also, should we consider 3rd party libs? like: https://github.com/kthompson/glob |
btw globstar is on the .NET Core radar: |
I think PathTooLongException only happens on Windows, but it's entirely possible to hit this when working on a project that's under a nested folder path if it has it's own deep folder tree. Since users of Windows PowerShell greatly overwhelm any users of PowerShell on Linux or Mac, I think it makes sense to guard for cases that might be Windows-only while still giving the best possible language experience. Before switching back to the old method, I'd recommend changing the current algorithm to not use the IEnumerable-returning EnumerateDirectories/EnumerateFiles since it will cause directory handles to be kept open while delving through larger file trees. Here's the code where file enumeration happens on Unix machines: If you change those EnumerateDirectories/Files calls to GetDirectories/Files, it might take care of the problem. There's really no benefit to using the Enumerate variety since we're not streaming the results back anyway, it just seemed to be the right thing to do at the time. |
@daviwil wow. Changing to Get* just works. Good call! I'll send out a PR |
…missing-snippets Fix syntax error in snippets file.
Seems we're hitting OS limits for file handles while walking the project's folder structure.
Relevant stack trace:
Related issues:
The text was updated successfully, but these errors were encountered: