nodemon: Bug report: Execution option run twice instead of one
I run following command
$> nodemon --ext lua --exec 'lunit test/test_SetCommandAdapter.lua'
For first run, so far so good
6 Jun 10:19:17 - [nodemon] v1.2.0
6 Jun 10:19:17 - [nodemon] to restart at any time, enter `rs`
6 Jun 10:19:17 - [nodemon] watching: *.*
6 Jun 10:19:17 - [nodemon] starting `lunit test/test_SetCommandAdapter.lua`
Loaded testsuite with 3 tests in 1 testcases.
...
12 Assertions checked.
Testsuite finished (3 passed, 0 failed, 0 errors).
6 Jun 10:19:17 - [nodemon] clean exit - waiting for changes before restart
However, if there is any file changes, nodemon runs execution twice.
6 Jun 10:19:17 - [nodemon] clean exit - waiting for changes before restart
6 Jun 10:21:03 - [nodemon] restarting due to changes...
6 Jun 10:21:03 - [nodemon] starting `lunit test/test_SetCommandAdapter.lua`
Loaded testsuite with 3 tests in 1 testcases.
...
12 Assertions checked.
Testsuite finished (3 passed, 0 failed, 0 errors).
6 Jun 10:21:03 - [nodemon] clean exit - waiting for changes before restart
6 Jun 10:21:03 - [nodemon] restarting due to changes...
6 Jun 10:21:03 - [nodemon] starting `lunit test/test_SetCommandAdapter.lua`
Loaded testsuite with 3 tests in 1 testcases.
...
12 Assertions checked.
Testsuite finished (3 passed, 0 failed, 0 errors).
6 Jun 10:21:03 - [nodemon] clean exit - waiting for changes before restart
Interestingly, no problems on typing rs manually.
6 Jun 10:21:03 - [nodemon] clean exit - waiting for changes before restart
rs
6 Jun 10:21:32 - [nodemon] starting `lunit test/test_SetCommandAdapter.lua`
Loaded testsuite with 3 tests in 1 testcases.
...
12 Assertions checked.
Testsuite finished (3 passed, 0 failed, 0 errors).
6 Jun 10:21:32 - [nodemon] clean exit - waiting for changes before restart
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 24 (8 by maintainers)
You got it! It doesn’t happen with v4.2.3 LTS.
However, I dug a bit deeper and found out that it might have to do something with the kqueue filesystem event system. Why? I used fswatch (https://github.com/emcrisostomo/fswatch) which allows to observe file changes and to choose different ways to do so depending on the OS you are running. On OS X, it’s FSevents, kqueue and polling. I used these steps to reproduce this nodemon issue’s behavior exactly with fswatch:
fswatch -o foo.jswill print “1” and a newline for each detected change event.So I piped this to
xargsand calleddateto get a timestamp for each event:Okay, I saved it 3 times in 4 seconds intervals. That’s what I did, no problem here.
On OS X, fswatch uses
FSEventsas default monitor. Now let’s change this to polling:Again, the output shows exactly what I did. No problem here, too.
Now let’s see what using kqueue as monitor will result in:
Whoops, there we go! I modified the file at second 11, 14 and 17 but we got 9 events from that monitor.
Now I wanted to see the timestamp of those events in a more detailed resolution but I couldn’t find a way to see milliseconds using the OS X’s date tool. So I created my own unix timestamp tool:
Compile with
gcc getTimestamp.c -o getTimestampIt tells us the current time as Unix time including milliseconds and microseconds:Now, let’s use this with fswatch and the kqueue monitor:
There we have a nice timing sequence of the events. The annoying ‘ghost’-event comes twice. First within less than 1 millisecond and then again after a second. The latter one is what we notice here with nodemon regularly. The first one is so fast, that it
appears only sometimesaffects nodemon sometimes but not always and not for everyone . This fits 100% to my nodemon behavior with Node.js 5.Paradoxically, according to the documentation, Node 4.2.3 as well as 5.1.1 are using kqueue for files on OS X: https://nodejs.org/docs/v5.1.1/api/fs.html#fs_availability https://nodejs.org/docs/v4.2.3/api/fs.html#fs_availability
This might be a single symptom with multiple roots. Of course, the backup-file by Vim users is another root and maybe there are more. But looks like I can’t proof kqueue is a root, even if that’s the case for fswatch. Maybe the Node.js docs for 5.1.1 are not correct?