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

Restart loop in Linux #609

Closed
daaain opened this issue Aug 12, 2015 · 11 comments
Closed

Restart loop in Linux #609

daaain opened this issue Aug 12, 2015 · 11 comments

Comments

@daaain
Copy link

daaain commented Aug 12, 2015

I'm trying to get Nodemon (with Gulp-Nodemon) working with the official Docker Node 0.12 image, but after having spent hours on this there's literally nothing else I can try :(

When I change any file, the restart process just gets into a loop and tries to restart on every second.

Setting a delay doesn't seem to help, other than completely preventing restart. Btw it seems when passing the delay option via the Gulp-Nodemon config object it's treating the number as milliseconds instead of seconds, not sure why.

Actually, could this loop happen because of using babel-node? The watch is aimed at the raw source file though.

Here's the full, minimal repo with the problem present: https://github.com/ustwo/docker-node-boilerplate

The relevant bit in my Gulpfile:

return nodemon({
      // dump: true,
      delay: 10000,
      verbose: true,
      script: 'src/server/index.js',
      watch: ['src/server', 'src/templates'],
      execMap: {
        js: 'babel-node'
      },
      ext: 'js html',
      env: {
        'NODE_ENV': 'development',
        'PORT': syncbrowser ? 8887 : 8888
      }
    }

Dump:

[16:38:44] [nodemon] v1.4.1
[16:38:44] [nodemon] to restart at any time, enter `rs`
[16:38:44] [nodemon] ignoring: .git /usr/local/src/node_modules/**/* bower_components .sass-cache
[16:38:44] [nodemon] watching: /usr/local/src/src/server/**/* /usr/local/src/src/templates/**/*
[16:38:44] [nodemon] watching extensions: js,html
[16:38:44] [nodemon] --------------
[16:38:44] [nodemon] node: v0.12.7
[16:38:44] [nodemon] nodemon: v1.4.1
[16:38:44] [nodemon] command: node /usr/local/src/node_modules/.bin/gulp watch --browsersync --dev
[16:38:44] [nodemon] cwd: /usr/local/src
[16:38:44] [nodemon] OS: linux x64
[16:38:44] [nodemon] --------------
[16:38:44] [nodemon] { run: false,
  system:
   { cwd: '/usr/local/src',
     useFind: true,
     useWatch: false,
     useWatchFile: false },
  required: true,
  dirs: [ '/usr/local/src/src/server', '/usr/local/src/src/templates' ],
  timeout: 1000,
  options:
   { dump: true,
     delay: 10000,
     verbose: true,
     watch: [ 'src/server', 'src/templates', re: /src/server|src/templates/ ],
     execMap: { js: 'babel-node', py: 'python', rb: 'ruby' },
     stdout: false,
     env: { NODE_ENV: 'development', PORT: 8887 },
     ignore:
      [ '.git',
        'node_modules',
        'bower_components',
        '.sass-cache',
        re: /\.git|node_modules|bower_components|\.sass\-cache/ ],
     restartable: 'rs',
     stdin: true,
     runOnChangeOnly: false,
     execOptions:
      { script: 'src/server/index.js',
        exec: 'babel-node',
        args: undefined,
        scriptPosition: undefined,
        nodeArgs: undefined,
        ext: 'js,html',
        env: { NODE_ENV: 'development', PORT: 8887 },
        execArgs: [] },
     monitor:
      [ '/usr/local/src/src/server/**/*',
        '/usr/local/src/src/templates/**/*',
        '!.git',
        '!/usr/local/src/node_modules/**/*',
        '!bower_components',
        '!.sass-cache' ] },
  load: [Function],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  command:
   { raw: { executable: 'babel-node', args: [ 'src/server/index.js' ] },
     string: 'babel-node src/server/index.js' },
  offset: 0 }
[16:38:44] [nodemon] --------------

Loop without delay:

[16:40:23] [nodemon] files triggering change check: src/server/index.js
[16:40:23] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:40:23] [nodemon] changes after filters (before/after): 1/1
[16:40:23] [nodemon] restarting due to changes...
[16:40:23] [nodemon] src/server/index.js
[16:40:23] [nodemon]
[16:40:23] [nodemon] starting `babel-node src/server/index.js`
[16:40:23] Nodemon restart...
[16:40:23] [nodemon] child pid: 50
[16:40:24] [nodemon] files triggering change check: src/server/index.js
[16:40:24] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:40:24] [nodemon] changes after filters (before/after): 1/1
[16:40:24] [nodemon] restarting due to changes...
[16:40:24] [nodemon] src/server/index.js
[16:40:24] [nodemon]
[16:40:24] [nodemon] starting `babel-node src/server/index.js`
[16:40:24] Nodemon restart...
[16:40:24] [nodemon] child pid: 59
[16:40:25] [nodemon] files triggering change check: src/server/index.js
[16:40:25] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:40:25] [nodemon] changes after filters (before/after): 1/1
[16:40:25] [nodemon] restarting due to changes...
[16:40:25] [nodemon] src/server/index.js
[16:40:25] [nodemon]
[16:40:25] [nodemon] starting `babel-node src/server/index.js`
[16:40:25] Nodemon restart...
[16:40:25] [nodemon] child pid: 67

Loop with delay:

[16:41:21] [nodemon] files triggering change check: src/server/index.js
[16:41:21] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:41:21] [nodemon] changes after filters (before/after): 1/1
[16:41:21] [nodemon] delaying restart for 10000ms
[16:41:22] [nodemon] files triggering change check: src/server/index.js
[16:41:22] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:41:22] [nodemon] changes after filters (before/after): 1/1
[16:41:22] [nodemon] delaying restart for 10000ms
[16:41:23] [nodemon] files triggering change check: src/server/index.js
[16:41:23] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:41:23] [nodemon] changes after filters (before/after): 1/1
[16:41:23] [nodemon] delaying restart for 10000ms
[16:41:24] [nodemon] files triggering change check: src/server/index.js
[16:41:24] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:41:24] [nodemon] changes after filters (before/after): 1/1
[16:41:24] [nodemon] delaying restart for 10000ms
[16:41:25] [nodemon] files triggering change check: src/server/index.js
[16:41:25] [nodemon] matched rule: **/usr/local/src/src/server/**/*
[16:41:25] [nodemon] changes after filters (before/after): 1/1
[16:41:25] [nodemon] delaying restart for 10000ms
@daaain
Copy link
Author

daaain commented Aug 14, 2015

Actually, now it gets into a loop even on startup :(

So how does watch work when using find? Is it looking at timestamps or doing checksums? If the former, could it be that it's a clock sync issue between the host and the VM?

Also, how does it normally resolve the update to move on?

@ghost
Copy link

ghost commented Aug 23, 2015

Isn't the problem you are using babel-node to run the code?

@daaain
Copy link
Author

daaain commented Aug 23, 2015

@bucaran I don't know, in theory you should even be able to use Nodemon for Ruby or Python as far as I understood: https://github.com/remy/nodemon#running-non-node-scripts

But it feels like the problem is with the file system change watching subsystem not with what's being executed.

Anyway, I wouldn't want to go back to ES5 just to make Nodemon happy, but thanks a lot for taking the time to have a look and the idea!

@ghost
Copy link

ghost commented Aug 23, 2015

I stumble upon this as I was trying to use nodemon to restart a running npm script on tree changes and I was also running stuff with babel-node. Your use case seems different, but I was able to do what I needed with watch, like this.

@daaain
Copy link
Author

daaain commented Aug 23, 2015

Just had a look, I'm using Gulp to watch what to build on the front end, but was trying to use Nodemon specifically to restart the Node server when server side files are changed.

So what you're suggesting is to work Nodemon out of the equation and use Gulp (or any other) watch to restart the server "manually"?

@ghost
Copy link

ghost commented Aug 23, 2015

If you are only using gulp to fire nodemon, then you certainly don't need gulp, but you may be doing other things and I see you are passing some configuration into nodeman, so if you are more comfortable with code than writing a bunch of flags, that's okay.

When I change any file, the restart process just gets into a loop and tries to restart on every second.

That looks like a bug in the code that sets up the watcher, but could also be a bug in your end if you are causing any mutations inside the watched tree. For example watch (the link I posted above) will run the specified command once (bootstrapping) which is usually what you want, but I must be careful not to run a script that will cause the same directory / file to change. If you can discard that is not the issue that'd be great.

@daaain
Copy link
Author

daaain commented Aug 23, 2015

There shouldn't be any changes in the watched files, both the Handlebars compilation in the HTML and the Babel JS transpiling should happen runtime.

I went through my setup and debug output several times and couldn't see anything out of place, so I think the bug must be on Nodemon (or dependency) side.

My feeling is that the problem might be due to the virtualised filesystem within Docker, but I didn't have time to dig deep enough to debug that, being unfamiliar with library code.

@remy
Copy link
Owner

remy commented Aug 30, 2015

Can you add the --verbose flag to start up. It'll tell you what's triggering the restart.

There is some logic that attempts to work out your docker clock offset - since it doesn't match the timestamp on the files (I suspect the clock is in the past, so the change timestamp is in the future).

@remy
Copy link
Owner

remy commented Aug 30, 2015

Sorry, I just saw you did. Can you try another thing - though I don't know what the fix is:

  • what's the date in the docker
  • find the index.js file, check the date
  • touch the index.js file, check the date

@remy
Copy link
Owner

remy commented Aug 31, 2015

Please try the build here #625 and feedback against the issue #625.

@remy
Copy link
Owner

remy commented Sep 12, 2015

#625 closes and released in [email protected]

@remy remy closed this as completed Sep 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants