C
C#2mo ago
Mazranel

FileSystemWatcher causes user limit exceptions on Kubuntu Linux

Using the following code results in the exception The configured user limit (128) on the number of inotify instances has been reached, or the per-process limit on the number of open file descriptors has been reached.:
public static void Init(string ProjectPath, List <ProjectFile> ProjectFileList, List <ProjectDirectory> ProjectDirList, List <Icon> IconList)
{
ProjectFiles = ProjectFileList;
ProjectDirs = ProjectDirList;
Icons = IconList;

FSWatcher.BeginInit();
FindItemsInProjectDirectory(null, null);

FSWatcher.IncludeSubdirectories = true;
FSWatcher.EnableRaisingEvents = true;
FSWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
FSWatcher.Changed += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Created += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Deleted += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Renamed += new RenamedEventHandler(FindItemsInProjectDirectory);
FSWatcher.Path = ProjectPath;
FSWatcher.EndInit();
}
public static void Init(string ProjectPath, List <ProjectFile> ProjectFileList, List <ProjectDirectory> ProjectDirList, List <Icon> IconList)
{
ProjectFiles = ProjectFileList;
ProjectDirs = ProjectDirList;
Icons = IconList;

FSWatcher.BeginInit();
FindItemsInProjectDirectory(null, null);

FSWatcher.IncludeSubdirectories = true;
FSWatcher.EnableRaisingEvents = true;
FSWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
FSWatcher.Changed += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Created += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Deleted += new FileSystemEventHandler(FindItemsInProjectDirectory);
FSWatcher.Renamed += new RenamedEventHandler(FindItemsInProjectDirectory);
FSWatcher.Path = ProjectPath;
FSWatcher.EndInit();
}
FindItemsInProjectDirectory does not do anything with the fs watcher object.
17 Replies
Mazranel
Mazranel2mo ago
I read that I could modify this limit, but that's just a workaround instead of a real solution. It also doesn't work well for portable applications.
Petris
Petris2mo ago
it's either that or having a background thread that call Directory.EnumerateFiles in a loop
Mazranel
Mazranel2mo ago
But doesn't it already run on a separate thread?
Omnissiah
Omnissiah2mo ago
what gave you this impression?
Mazranel
Mazranel2mo ago
The application runs without any delays or freezing, even with a large amount of files. That's flawed though now that I think about it
wasabi
wasabi2mo ago
The issue is INcludeSubdiretories, probably. It's been awhile since I looked, but from what I remember it opens a new inotify channel for each watched directory. And Linux limits those.
Mazranel
Mazranel2mo ago
Ah. There really aren't thatany subdirectories though, is there a way to work around this?
wasabi
wasabi2mo ago
Nope. Gotta increase the per-user limit. Actually, looking at your error, it's not erroring because of max watches, but because of max instances. Might be the case you're creating too many FSWs
Mazranel
Mazranel2mo ago
I should only be creating one, I'll add a console.writeline in the fs watcher init function Yeah it's only creating one instance as far as I'm aware
Petris
Petris2mo ago
for context, the limit that's hit is usually the global one not the per app one also why do you have it at 128
Petris
Petris2mo ago
the default seems to be 8192
No description
wasabi
wasabi2mo ago
watch != instance
Mazranel
Mazranel2mo ago
That seems to be Kubuntu's default Nvm, just read the above comment Ah. I'm not sure what else could be causing the limit to be hit though, as there are only about 3 applications running at a time
wasabi
wasabi2mo ago
You can probably check something in procfs to see how many are used
Mazranel
Mazranel2mo ago
I could add a check before the few gets set up
wasabi
wasabi2mo ago
or you could just go look. with your eyes
Mazranel
Mazranel2mo ago
I meant as a warning for users. Y'know, so they don't just have to deal with some random error that might look like gibberish to them We don't want Microsoft error messages
Want results from more Discord servers?
Add your server