fsharp / emacs-fsharp-mode

F# Emacs mode
Apache License 2.0
208 stars 62 forks source link

Add workaround for file watcher issue in FSAC on OS X #205

Closed kqr closed 5 years ago

kqr commented 5 years ago

This is the best workaround I've found so far. Without it, I cannot even load the simplest of project files.

Fixes issue #204.

juergenhoetzel commented 5 years ago

This is the best workaround I've found so far. Without it, I cannot even load the simplest of project files.

Fixes issue #204.

I wonder what negative effects this change could have:

MONO_MANAGED_WATCHER=disabled"

IIRC the watcher is used by fsautocomplete.exe to track changes on project files.

It seems like a leak of file descripors. On my Arch Linux system only 9 inotify file descriptors are allocated (using your sample project):

juergen@lemmy:~/fsharp/test → lsof -n -p $(pgrep -f fsautocomplete.exe)|grep inotify
mono    869 juergen    4r  a_inode   0,13        0   11770 inotify
mono    869 juergen    5r  a_inode   0,13        0   11770 inotify
mono    869 juergen    6r  a_inode   0,13        0   11770 inotify
mono    869 juergen    7r  a_inode   0,13        0   11770 inotify
mono    869 juergen    8r  a_inode   0,13        0   11770 inotify
mono    869 juergen    9r  a_inode   0,13        0   11770 inotify
mono    869 juergen   10r  a_inode   0,13        0   11770 inotify
mono    869 juergen   11r  a_inode   0,13        0   11770 inotify
mono    869 juergen   12r  a_inode   0,13        0   11770 inotify

Can you check this out on macos using similar tools? Thanks!

kqr commented 5 years ago

Are you asking me to check for allocated file descriptors when I'm running with MONO_MANAGED_WATCHER=disabled or with the "managed watcher" (whatever it is)? To be clear: I cannot even start running fsautocomplete.exe with the managed watcher because it quits right away.

If I'm allowed to guess wildly, I would suspect it's using some sort of filesystem watcher API that either a) does not exist in modern OS X releases, or at least b) is protected by some sort of security measure. But I don't know enough about OS X to make a more educated guess than that – I'm forced to use the operating system at work, but I'm not interested enough in it to learn a lot about it...

kqr commented 5 years ago

There is also this that I found: https://github.com/fsharp/FsAutoComplete/issues/331#issuecomment-484730743

kqr commented 5 years ago

Turns out if I install mono from www.mono-project.com instead of homebrew (one of the more popular package managers for OS X), FSAC loads projects just fine without workaround, and running the lsof command you suggested shows me a bunch of KQUEUE entries which I think is what corresponds to inofity in the BSD/OS X world.

So I retract this pull request, but if it's possible to detect this situation (i.e. Mono installed from homebrew and exception relating to FileWatcher when trying to load project file) and throw a more helpful error message suggesting to download and install from www.mono-project.com instead, that'd be a good idea. At least if this issue with Mono from homebrew is going to be long-lived.