Bug 28516 - Setting FileSystemWatcher.EnableRaisingEvents to true hangs in some cases
Summary: Setting FileSystemWatcher.EnableRaisingEvents to true hangs in some cases
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.12.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-28 11:35 UTC by xamarin
Modified: 2016-04-16 09:44 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 28516 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description xamarin 2015-03-28 11:35:26 UTC
The following code hangs:

private System.IO.FileSystemWatcher _fsw;

void InitFSW()
{
    _fsw = new System.IO.FileSystemWatcher();
    _fsw.Path = "/dev";
    _fsw.Filter = "tty.*";
    _fsw.IncludeSubdirectories = false;
    _fsw.Created += Fsw_Created;
    _fsw.Deleted += Fsw_Deleted;
    _fsw.EnableRaisingEvents = true; // << this hangs
}

The issue is that watch is on the /dev directory. "Normal" directories do not exhibit this problem. Have not investigated other such directories.

The call stack of the hang is:
System.Threading.WaitHandle.WaitOne_internal () in 
System.Threading.WaitHandle.WaitOne () in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/corlib/System.Threading/WaitHandle.cs:357
System.IO.KqueueMonitor.Start () in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.IO/KeventWatcher.cs:197
System.IO.KeventWatcher.StartDispatching (fsw={System.IO.FileSystemWatcher}) in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.IO/KeventWatcher.cs:649
System.IO.FileSystemWatcher.Start () in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.IO/FileSystemWatcher.cs:507
System.IO.FileSystemWatcher.set_EnableRaisingEvents (value=true) in /private/tmp/source-mono-mac-3.12.0-branch-32/bockbuild-mono-3.12.0-branch/profiles/mono-mac-xamarin/build-root/mono-3.12.1/mcs/class/System/System.IO/FileSystemWatcher.cs:218
...

There is a workaround.

void InitFSWWorkaround()
{
    Environment.SetEnvironmentVariable ("MONO_MANAGED_WATCHER", "1");
    _fsw = new System.IO.FileSystemWatcher();
    _fsw.Path = "/dev";
    _fsw.Filter = "tty.*";
    _fsw.IncludeSubdirectories = false;
    _fsw.Created += Fsw_Created;
    _fsw.Deleted += Fsw_Deleted;
    _fsw.EnableRaisingEvents = true; // << this hangs
}
Comment 1 xamarin 2015-03-28 12:10:13 UTC
Looking at the thread the KqueueMonitor thread uses, it's stuck trying to open "/dev/tty.Bluetooth-PDA-Sync".  Specifically:

int fd = open (fullPathNoLastSlash, O_EVTONLY, 0);