Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File watching worked in 0.12.1 but does not in newer versions with Vagrant/Virtualbox/NFS shared folders configurations #931

Closed
43n79w opened this issue Jan 10, 2015 · 16 comments

Comments

@43n79w
Copy link

43n79w commented Jan 10, 2015

Using Vagrant (1.7.2) with Virtualbox (4.3.20) on Mac OS X 10.10.1 and a Vagrant configuration which does the following:

  • Uses Vagrant's build-in docker support to provision a virtual machine that mounts a NFS shared folder. This shared folder is exposed as a docker volume.
  • Launches several docker containers, one of which runs PM2 to launch a Node.JS script. PM2 watches a sub-directory of the above docker volume.

In version 0.12.1 of PM2, I could edit a watched file on my Mac OS X host and PM2 would correctly restart the application. In (at least) 0.12.3 of PM2, this is no longer the case. If I SSH into the Virtualbox and touch the same file there, PM2 restarts the application.

I've debugged this for a couple of days and tried many different Vagrant/Virtualbox/Docker configurations thinking the issue lay there. But on a whim I tried installing an older version of PM2 that had been working in a similar project, and things started to work. I noticed that there were some file watching changes in 0.12.2. Perhaps some of these changes are causing this behaviour?

@Tjatse
Copy link
Collaborator

Tjatse commented Jan 12, 2015

We updated dependencies (chokidar) around v0.12.1, can you help to figure out whether this problem is related to chokidar or not?

var chokidar = require('chokidar');
var watcher = chokidar.watch('current directory', {
  ignored: /[\/\\]\.|node_modules/, 
  persistent: true,
  ignoreInitial : true
}).on('all', function(event, path) {
  console.log(event, path);
});

Appreciate!

@43n79w
Copy link
Author

43n79w commented Jan 12, 2015

Thanks @Tjatse. I can confirm that the issue appears to lie in chokidar. I ran the above test against chokidar ~0.10.1 which was the previous PM2 dependency and was able to trigger the logging message by writing from the host machine. But when I upgraded chokidar ~0.12.1 which is the new PM2 dependency, writes from the host machine would not trigger the logging message.

@Tjatse
Copy link
Collaborator

Tjatse commented Jan 13, 2015

@43n79w Thats nice, and thanks a lot. Can you describe this on chokidar issues? and reference to this by using Unitech/PM2#931, maybe chokidar team could give us an advice. :p

@caseywebdev
Copy link

I ran into this issue in my own project using chokidar w/ vagrant/parallels/boot2docker. The problem is that the atomic file watching option is being defaulted to when, over NFS, your only option is file polling as inotify events will not be triggered. My solution was to add a command line option to opt into usePolling and now everything is working again.

@soyuka
Copy link
Collaborator

soyuka commented Jan 15, 2015

is being defaulted to when

Is there missing a word? So, @caseywebdev what's your solution? Setting usePolling to false?

@Tjatse
Copy link
Collaborator

Tjatse commented Jan 16, 2015

maybe we should expose all the chokidar options.

@soyuka
Copy link
Collaborator

soyuka commented Jan 16, 2015

Indeed it'd also fix #870 (followSymlink)

@caseywebdev
Copy link

Sorry, it defaults to atomic on Linux which is why you need to explicitly set usePolling: true to get chokidar working over NFS. You may also want to set boot_options: %w[actimeo=2] in your Vagrantfile sync settings so that NFS will update mtimes more often than the default (which is like 15s).

@reimerp
Copy link

reimerp commented Jan 21, 2015

Hi, I can confirm this bug, using Linux with local file systems only. PM2 Version 0.12.1 is working, 0.12.2 and 0.12.3 is continously restarting the app. Tried some debugging on pm2:watch but this seem not even involved...

@soyuka soyuka closed this as completed in 8a373e1 Jan 29, 2015
jshkurti added a commit that referenced this issue Jan 29, 2015
@rarkins
Copy link

rarkins commented Jan 29, 2015

@soyuka what is the actual fix/resolution?

@soyuka
Copy link
Collaborator

soyuka commented Jan 29, 2015

You can now change chokidar options through the watch_options variable in the schema.

@caseywebdev wrote:

I ran into this issue in my own project using chokidar w/ vagrant/parallels/boot2docker. The problem is that the atomic file watching option is being defaulted to when, over NFS, your only option is file polling as inotify events will not be triggered. My solution was to add a command line option to opt into usePolling and now everything is working again.

So, you can change the atomic parameter to true or false or change the usePolling parameter to fit your needs.
If I understood this issue, it wasn't really pm2-related more chokidar-related. Try playing with those parameters and if you can't fix it please come back to us!

/edit:

I've added some docs about the chokidar use: https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#watch--restart.

PM2 is giving those default options to chokidar:

var watch_options = {
  persistent    : true,
  ignoreInitial : true
}

Other options are the one defined by chokidar, for example usePolling is false.

/edit 2: while using NFS use usePolling: true see #1062

MichielDeMey added a commit to astromo/astromo-vagrant that referenced this issue Apr 4, 2015
This allows us to set watch options, see Unitech/pm2#931
@yads
Copy link

yads commented Jul 17, 2015

It still doesn't seem to be working for me with the following options:

  "watch": true,
  "watch_options": {
    "usePolling": true,
    "useFsEvents": false,
    "atomic": false
  }

Am I missing something?

@soyuka
Copy link
Collaborator

soyuka commented Jul 17, 2015

What's your setup?

Are you using os x? NFS?

@yads
Copy link

yads commented Jul 17, 2015

We're using nfs to mount OSX folder to Linux.
On Jul 17, 2015 11:50 AM, "Antoine Bluchet" notifications@github.com
wrote:

What's your setup?

Are you using os x ? NFS ?


Reply to this email directly or view it on GitHub
#931 (comment).

@soyuka
Copy link
Collaborator

soyuka commented Jul 18, 2015

So, just tried this exact configuration "watching an nfs mounted directory from os x".

I just left the default settings and it worked, it seems that fsEvents are doing just fine compared to the nodejs default file system events.

My recommendation with your settings will be to:

  1. Make sure that the optional dependency "fsevents" has been build
  2. Don't use polling but keep fsEvents useFsEvents: true

I don't know why you'd need atomic here, the default setting seems to work fine. According to the chokidar Readme it appears that this setting is automatically set according to the other options.

If it doesn't work, you can also use usePolling: true. I just tried with both fsEvents vs usePolling and both are working here.

Client OS X 10.10.3 + pm2 0.14.3 + node 0.12.4
NFS Server on OS X 10.9.5

@yads
Copy link

yads commented Jul 18, 2015

Thanks for the investigation. I'll have to try it out with 0.12.4. We're currently using iojs 2.3.x so maybe that has some issues. I also haven't built fsevents so I'll take a look at that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants