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)

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


Attachments

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);

Note You need to log in before you can comment on or make changes to this bug.