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

Overkill Restarting On File Opening #1208

Closed
atom0s opened this issue Jan 6, 2018 · 27 comments
Closed

Overkill Restarting On File Opening #1208

atom0s opened this issue Jan 6, 2018 · 27 comments
Labels
can't replicate needs more info not enough information in issue to debug stale no activity for 2 weeks windows

Comments

@atom0s
Copy link

atom0s commented Jan 6, 2018

  • nodemon -v: 1.14.7
  • node -v: 8.9.4
  • Operating system/terminal environment: Windows 10 (and Windows 8.1)
  • Command you ran:

nodemon

Expected behaviour

Restarts triggered when a source file is altered.

Actual behaviour

Restarts are triggering just opening the files in an editor such as VSCode.

Steps to reproduce

  1. Install node.
  2. Install nodemon.
  3. Run nodemon in a source directory.
  4. Open the source in VSCode and just click in the file browser to open the file in the editor.

Soon as the file is opened, Nodemon will trigger a restart/refresh.

Seems a bit overkill to be triggering just when the file is opened in an editor such as VSCode. If I run with legacy mode (-L) this stops happening but then I have the issue of every file being polled excessively as the docs state.

Everything is working as it should otherwise, but the retriggering while using VSCode seems a bit excessive. I can't find any way to turn this off either or prevent it from happening so that it goes back to only updating when a file is saved.

@atom0s
Copy link
Author

atom0s commented Jan 6, 2018

Running with verbose mode on, the trigger is seen as:

[nodemon] files triggering change check: some\file\path\data\1000.json
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] some\file\path\data\1000.json

Just clicking on the 1000.json file to open it in VSCode editor causes the trigger and restart.

@remy
Copy link
Owner

remy commented Jan 6, 2018

What, in Windows, are you using to run nodemon? Is it the command prompt, powershell, git bash, or something else? Also, I suspect this is because somehow the OS is triggering a notify of file change - rather than nodemon doing anything special…

@remy remy added needs more info not enough information in issue to debug windows labels Jan 6, 2018
@atom0s
Copy link
Author

atom0s commented Jan 6, 2018

I am using Powershell.

@remy
Copy link
Owner

remy commented Jan 6, 2018

@atom0s are you able to replicate in a non-powershell? (just to rule out vs code or something more general)

@atom0s
Copy link
Author

atom0s commented Jan 6, 2018

Yes, it happens with a normal command prompt as well. Just tested.
Updated to latest nodemon (1.14.8) and is still happening as well.

It does seem to be random when it will happen. Trying to trigger it constantly does not work and replicating it takes a few launches to get it to happen each time.

@remy
Copy link
Owner

remy commented Jan 9, 2018

Can you re-test with [email protected]? There's been a few changes that might affect your testing (I couldn't replicate with powershell on my own windows machine).

@SpencerKaiser
Copy link

I'm having a similar issue... when using atom if I have multiple files open (not just being previewed) and I switch between them (e.g., switch tabs), the file I switch to is triggering a restart. No saves are taking place and nothing should be modifying those files.

Just updated and verified the issue again with [email protected], please let me know if any other info would be helpful!

@remy
Copy link
Owner

remy commented Jan 14, 2018

@SpencerKaiser can you include a screenshot of the nodemon output with --verbose flag when it's restarting. I'm suspecting the editor touching some files, but I can't replicate this at all so it's hard to know.

@SpencerKaiser
Copy link

@remy Huh... now the behavior is changing up a bit and it's only triggering when I switch to certain files. Here's the output when I switched between several files with flight.js being the only one that triggered the restart. I had just saved that file a few mins prior and the others have been untouched since my last commit 🤔

[nodemon] files triggering change check: api/controllers/flight.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] api/controllers/flight.js

[nodemon] starting `node app.js`
[nodemon] forking
[nodemon] child pid: 13127
App listening on  3030
Connected to DB


Setup complete!
[nodemon] files triggering change check: data/diagnostic.data/metrics.interim
[nodemon] changes after filters (before/after): 1/0
[nodemon] files triggering change check: api/controllers/flight.js
[nodemon] matched rule: **/*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] api/controllers/flight.js

[nodemon] starting `node app.js`
[nodemon] forking
[nodemon] child pid: 13131
App listening on  3030
Connected to DB


Setup complete!

@SpencerKaiser
Copy link

Maybe git is modifying files or my editor is modifying them for me on git's behalf because it seems like the restart only triggers for files with unstaged changes

@atom0s
Copy link
Author

atom0s commented Jan 14, 2018

Sorry for the delayed response, been busy with holidays and family etc. It is hard to reproduce this consistently, it seems to happen at random for me as well similar to what Spencer mentioned in his above response. Sometimes a file will trigger, sometimes it won't. I have to restart VSCode to get it to start happening again sometimes. So it seems very random and inconsistent.

One thing I will say is that for me, Git is not related as it was happening on a folder/project that was not in any type of repository and was just local to the system.

Here is an example with latest nodemon. In a semi-large project with a lot of packages installed. Opening the yarn.lock file for "preview" mode in VSCode (ie. click it once it opens a preview/temp window vs. a full editor until you either double click the file or start typing in the editor.) This triggers nodemons change check.

procmon shows this for the node process running nodemon:

https://i.imgur.com/14q6a1T.png

It hits the main specific file (in this case yarn.lock) first, then loops the entire project afterward in the same manner.

@remy
Copy link
Owner

remy commented Jan 18, 2018

@atom0s I'm not familiar with procmon, so I'm not sure why (or what) is walking through your current working path, but can you include the output of nodemon -V so I can look for any config that might help diagnose.

Like I said, I can't replicate at the moment, so I'm unsure of where the root of the issue is.

@alexisdiel
Copy link

When express requests the file to render view, it detects as a change and reloads

[14:41:35] [nodemon] files triggering change check: views\card.pug
[14:41:35] [nodemon] matched rule: **.
[14:41:35] [nodemon] changes after filters (before/after): 1/0

@remy
Copy link
Owner

remy commented Jan 24, 2018

@alexisdiel I'm guessing you have a nodemon config in place, only because you're currently watching everything with **.

@alexisdiel
Copy link

Sure @remy
I'm using it along with browserSync and fixed by not watching some folders, configuring the browserSync to watch these folders.

@remy
Copy link
Owner

remy commented Jan 25, 2018

@atom0s still waiting on a reply. Any chance you're able to follow up? Or I can close and re-open if others are seeing this issue (in a way that it's replicable).

@stale
Copy link

stale bot commented Feb 8, 2018

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Feb 8, 2018
@stale stale bot closed this as completed Feb 15, 2018
@mikemaccana
Copy link
Contributor

Same as @alexisdiel - express opens a hbs file and it triggers an update. I should be able to produce a minimal test case to help replicate if needed/wanted.

@arasmussen
Copy link

Not sure what the issue is, but reinstalling fixed for me.

npm uninstall -g nodemon
npm install -g nodemon

@AbdelrahmanHafez
Copy link

AbdelrahmanHafez commented May 25, 2018

For me, it used to happen on the node app itself opening files using require(...), a restart with each file.

It may be related to HBS, since we started relying on it heavily when this first started to happen. However, uninstalled & reinstalled nodemon to version 1.17.5, no restarts yet. Will comment here again if the issue is back again.

Edit: Nope, the issue still exists.

@akwilson
Copy link

akwilson commented Jun 5, 2018

I am also affected by this issue, but only since the 1803 Window Update in April.

Node; v8.11.1
Nodemon: v1.17.3
Windows 10 build 1803
Ubuntu on WSL v16.04.4

Something is triggering a restart when opening a file, but not consistently. Restarts are also triggered almost at random for no obvious reason. I checked the timestamps on the files on the project -- they are not updating.

Actually, I don't think this is a problem with nodemon specifically. I'm adding my comment here because this thread is the closest thing I have found to anyone else suffering from this problem! I also have a React project that uses webpack which also suffers from similar annoying restarts.

@mikemaccana
Copy link
Contributor

mikemaccana commented Jun 5, 2018

This is with no editors open, just running gulp-nodemon, and with verbose enabled

[13:07:10] [nodemon] 1.17.4
[13:07:10] [nodemon] to restart at any time, enter `rs`
[13:07:10] [nodemon] watching: C:\Users\mike\Documents\certsimple\routes/**/* C:\Users\mike\Documents\certsimple\views/**/*
[13:07:10] [nodemon] watching extensions: js
[13:07:10] [nodemon] starting `node bin/www debug`
[13:07:10] [nodemon] forking
[13:07:10] [nodemon] child pid: 16500
  Finished JS bundle index.
[13:07:11] [nodemon] watching 15 files
  Finished JS bundle order-management.
[13:07:11] [nodemon]
[13:07:11] [nodemon] files triggering change check: routes\index.js
[13:07:11] [nodemon] matched rule: C:\Users\mike\Documents\certsimple\routes/**/*
[13:07:11] [nodemon] changes after filters (before/after): 1/1
[13:07:11] [nodemon] restarting due to changes...
[13:07:11] [nodemon] Routes\index.js
[13:07:11] [nodemon] starting `node bin/www debug`
[13:07:11] [nodemon] forking
[13:07:11] [nodemon] child pid: 14020

Some interestng points:

  • It's the routes file triggering the updates, but it's definitely not changing.
  • The NTFS LastAccessTime is changing:
    $ date
    Tuesday, June 5, 2018 1:10:24 PM


    $ ls .\routes\index.js | select *

    CreationTime      : 13-Nov-17 1:42:07 PM
    CreationTimeUtc   : 13-Nov-17 1:42:07 PM
    LastAccessTime    : 05-Jun-18 1:07:12 PM
    LastAccessTimeUtc : 05-Jun-18 12:07:12 PM
    LastWriteTime     : 31-May-18 9:19:32 AM
    LastWriteTimeUtc  : 31-May-18 8:19:32 AM

So my general feeling is that LastAccessTime modifications are triggering restarts

@svogal
Copy link

svogal commented Jul 14, 2018

So my general feeling is that LastAccessTime modifications are triggering restarts

Yes!
Running this command as administrator did the trick:
fsutil behavior set disablelastaccess 1

@mikemaccana
Copy link
Contributor

Thanks for the confirmation @svogal. With that in mind I've checked this out looking at fixing it. Check out watch.js:52 - watcher sends it's results to filterAndRestart() but filterAndRestart() only gets a list of files, not what aspect of them changed - I was hoping to filter out LastAccessTime changes but it looks like that needs to be done in chokidar.

@mckenzieja
Copy link

@arasmussen

Your solution seemed to work for me.

I was running a node app with express using Pug (Jade) and the pug files were triggering the changes)

@mikemaccana
Copy link
Contributor

@remy this isn't stale, the issue (to sum up the discussion above) is fixed in paulmillr/chokidar#762 and once chokidar do a release, and nodemon uses it, the problem will go away.

@mikemaccana
Copy link
Contributor

I've raised a separate issue since thus one is closed - all nodemon needs to do is update chokidar.

remy added a commit that referenced this issue Feb 8, 2019
Fixes #1522
Fixes #1208

Thanks to @mikemaccana for original PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't replicate needs more info not enough information in issue to debug stale no activity for 2 weeks windows
Projects
None yet
Development

No branches or pull requests

10 participants