Bug 28693

Summary: IOException: kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.
Product: [Mono] Class Libraries Reporter: David Fowler <davidfowl>
Component: SystemAssignee: Bugzilla <bugzilla>
Severity: normal CC: chris.carroll, heavycrag, jarroda, miguel, miguel, mono-bugs+mono, shrutis, sornakumar, staessenmichiel, suhasbjoshi
Priority: ---    
Version: 3.12.0   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description David Fowler 2015-04-02 11:56:55 UTC
1. Clone `https://github.com/anurse/dnxb4signoff`
2. `cd src\DnxSignoff`
3. `dnu restore`
4. `dnx . kestrel`
5. :(

Expected: Pretty MVC stuff

![screen shot 2015-04-01 at 4 38 13 pm](https://cloud.githubusercontent.com/assets/7574/6955030/856cd5dc-d88d-11e4-98e0-0e62a9529401.png)
Comment 1 Michiel Staessen 2015-04-06 05:11:48 UTC
Also present in MDK 4.0.0
Comment 2 Miguel de Icaza [MSFT] 2015-04-07 18:09:57 UTC
We need a better repro than using dnu restore/dnx kestrel because those stacks are too large and I have failed repeatedly at getting them working with my custom build of Mono.

The resources on the web are also lacking.
Comment 3 Suhas 2015-04-30 14:29:18 UTC
Users are hitting this with 4.0.1 as well. More info at https://github.com/aspnet/Home/issues/508
Comment 4 sornakumar 2015-08-06 14:02:32 UTC
@Miquel de Icaza - https://github.com/aspnet/Home/issues/508#issuecomment-122305412 This comment mentions the scenario can be repro'd using Gulp and Sass.

Is dnu restore/dnx kestrel still not working for you? I can help you get them working if you give me the error you are encountering..
Comment 5 Chris F Carroll 2015-09-01 18:09:00 UTC
To reproduce this on OS X / Mono 4:
using System;
using System.IO;
public class WatcherFileLimit
    public static void Main()
        FileSystemWatcher watcher = new FileSystemWatcher();
        watcher.Path = "/";
        watcher.EnableRaisingEvents = true;
whereas the equivalent on .Net on Windows 10 (i.e. watcher.Path="\\") works fine.
Comment 6 Chris F Carroll 2015-09-01 18:15:31 UTC
Sorry let me be more precise. That was with mono version 4.2.0.

Reproduce it in the csharp repl with the lines:
using System.IO;
var w= new FileSystemWatcher{Path="/", IncludeSubdirectories=true, EnableRaisingEvents=true};

If you omit EnableRaisingEvents, then it doesn't throw.
Comment 7 Nate Cook 2015-12-04 20:42:52 UTC
I get this using dnx-watch kestrel. Running dnx kestrel works fine.

Comment 8 Nate Cook 2015-12-04 20:51:28 UTC
In my case the workaround was to put my code into a src folder and run dnx-watch there instead of at the root. The result of that was the exclusion of the .git folder in the root, which I assume was the problem since my project is quite small at this point.
Comment 9 Miguel Lira 2015-12-05 11:58:18 UTC
It appears there is hard coded max value of 200 for the number of dictionary entries that can be added to the watcher:


Once exceeded the exception is thrown:


Most .NET 5/MVC 6 developers will run into this limit due to the large number of files added to the bower_components and npm_modules folders.

This is most likely a limit imposed for some performance reason, but it would be great if someone on the Mono team could provide more feedback.
Comment 10 Miguel de Icaza [MSFT] 2015-12-09 00:29:26 UTC
Fixed, the limit is gone.
Comment 11 Shruti 2015-12-17 11:36:09 UTC
I have checked this issue with latest C6SR1 Mono  MonoFramework-MDK- using code snippet given in comment(5) and observed that Now no exception is raising on watcher.EnableRaisingEvents = true. 

Screencast: http://www.screencast.com/t/Jyr3Zc31r7

Environment Info:https://gist.github.com/shrutis360/3d269a8dede0da9640ad

Hence, Closing this issue.