Restart fails when running coffee with the --debug option #118

Closed
haircuttedfreak opened this Issue Aug 12, 2012 · 22 comments

Projects

None yet

5 participants

@haircuttedfreak

I can successfully run nodemon against coffee files: nodemon index.coffee
I can successfully run nodemon against js files with the --debug switch: nodemon --debug index.js
But I cannot run nodemon against coffee files with the --debug switch: nodemon --debug index.coffee.

I understand that I'm not actually debugging coffee, but the generated js files. The problem occurs when I change a js or coffee file and nodemon tries to restart the process:

debugger listening on port 5858

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                   ^
Failed to open socket on port 5858, waiting 1000 ms before retrying
Error: listen EADDRINUSE
    at errnoException (net.js:776:11)
    at Server._listen2._connectionKey (net.js:917:26)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

The problem is that when you run coffee with the --debug option, coffee spawns an extra node process that attaches itself to port 5858 for debugger. This is different from just running node --debug on a js file. So there are 2 processes that need to be killed when running coffee --debug. Since nodemon only kills one of them, when it restarts, it tries to recreate both process, but the old process is still holding on to port 5858 so it crashes.

I think the right approach is to kill the entire process tree, similar to what you are doing on windows. I'll submit a pull request for this.

@dhruvasagar

Has this been released yet ? I am still facing this issue.

@remy
Owner
@remy
Owner

Actually, I think this might be waiting to hit npm - I need to try to replicate this first...

@dhruvasagar

Ok, I just ran nodemon --debug app.coffee

@ElliotChong

+1, still hitting this issue regularly

@remy
Owner

Can you test nodemon@dev? This should be fixed on the latest branch.

@ElliotChong

Is there a different way to run CoffeeScript files in v0.9.7?

Went to test the debug flag in nodemon@dev and getting an error that doesn't occur in v0.7.10.

Elliots-MacBook-Pro-2:PurpleLoot elliot$ npm install -g nodemon
npm http GET https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/nodemon
/Users/elliot/.nvm/v0.10.21/bin/nodemon -> /Users/elliot/.nvm/v0.10.21/lib/node_modules/nodemon/nodemon.js
nodemon@0.7.10 /Users/elliot/.nvm/v0.10.21/lib/node_modules/nodemon
Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon web.coffee
15 Nov 10:41:55 - [nodemon] v0.7.10
15 Nov 10:41:55 - [nodemon] to restart at any time, enter `rs`
15 Nov 10:41:55 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
15 Nov 10:41:55 - [nodemon] starting `coffee web.coffee`
15 Nov 10:41:55 - [nodemon] reading ignore list
  purpleloot:core:log Starting application with 'development' configuration +0ms
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
  purpleloot:core:log Starting HTTP web server: http://127.0.0.1:4050 +647ms
  purpleloot:core:log Web server started ☺ +1ms
  purpleloot:model:log Connected to mongodb://127.0.0.1/purpleloot_dev +0ms
^C15 Nov 10:42:13 - [nodemon] exiting
Elliots-MacBook-Pro-2:PurpleLoot elliot$ npm install -g nodemon@dev
... npm installs ...
/Users/elliot/.nvm/v0.10.21/bin/nodemon -> /Users/elliot/.nvm/v0.10.21/lib/node_modules/nodemon/bin/nodemon.js
nodemon@0.9.7 /Users/elliot/.nvm/v0.10.21/lib/node_modules/nodemon
└── update-notifier@0.1.7 (semver@2.1.0, chalk@0.2.1, request@2.27.0, configstore@0.1.5)
Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon web.coffee
15 Nov 10:42:39 - [nodemon] v0.9.7
15 Nov 10:42:39 - [nodemon] to restart at any time, enter `rs`
15 Nov 10:42:39 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
15 Nov 10:42:39 - [nodemon] starting `coffee --nodejs web.coffee`

/Users/elliot/Dropbox/Sites/PurpleLoot/web.coffee:3
# # PurpleLoot web
^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3
15 Nov 10:42:39 - [nodemon] app crashed - waiting for file changes before starting...
@ElliotChong

It looks like v0.9.7 is adding a --nodejs to its starting command even when there aren't additional parameters to pass.

v0.7.10

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon web.coffee
...
15 Nov 10:41:55 - [nodemon] starting `coffee web.coffee`

v0.9.7

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon web.coffee
...
15 Nov 10:42:39 - [nodemon] starting `coffee --nodejs web.coffee`
@ElliotChong

When running v0.9.7 with the debug flag it will launch correctly (since a flag is now set to overcome the --nodejs issue), but it doesn't relaunch the app when modifying any of the files within the directory and I noticed it doesn't say 15 Nov 10:41:55 - [nodemon] reading ignore list like v0.7.10.

Log after modifying a few .coffee files within the project (expecting it to relaunch) which works correctly in v0.7.10:

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon --debug web.coffee
15 Nov 10:51:46 - [nodemon] v0.9.7
15 Nov 10:51:46 - [nodemon] to restart at any time, enter `rs`
15 Nov 10:51:46 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
15 Nov 10:51:46 - [nodemon] starting `coffee --nodejs --debug web.coffee`
debugger listening on port 5858
  purpleloot:core:log Starting application with 'development' configuration +0ms
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
  purpleloot:core:log Starting HTTP web server: http://127.0.0.1:4050 +646ms
  purpleloot:core:log Web server started ☺ +2ms
  purpleloot:model:log Connected to mongodb://127.0.0.1/purpleloot_dev +0ms
@remy
Owner

A quick note: the old ignore file isn't supported yet in 0.9 - but will be!

If the coffee script isn't running can you paste a simple example (I do have a coffee test but the more the better)

@ElliotChong

A simple repro would be creating test.coffee with just console.log "CoffeeScript!" inside.

Terminal Output:

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon test.coffee
15 Nov 12:18:41 - [nodemon] v0.9.7
15 Nov 12:18:41 - [nodemon] to restart at any time, enter `rs`
15 Nov 12:18:41 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
15 Nov 12:18:41 - [nodemon] starting `coffee --nodejs test.coffee`

/Users/elliot/Dropbox/Sites/PurpleLoot/test.coffee:1
ion (exports, require, module, __filename, __dirname) { console.log "CoffeeScr
                                                                    ^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3
15 Nov 12:18:41 - [nodemon] app crashed - waiting for file changes before starting...
^CElliots-MacBook-Pro-2:PurpleLoot elliot$ cat test.coffee
console.log "CoffeeScript!"

Looks like it's that --nodejs flag that's being appended without any subsequent flags.

To get it to run without an error, add the debug flag to nodemon: nodemon --debug test.coffee

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon --debug test.coffee
15 Nov 12:22:00 - [nodemon] v0.9.7
15 Nov 12:22:00 - [nodemon] to restart at any time, enter `rs`
15 Nov 12:22:00 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
15 Nov 12:22:00 - [nodemon] starting `coffee --nodejs --debug test.coffee`
debugger listening on port 5858
CoffeeScript!
15 Nov 12:22:00 - [nodemon] clean exit - waiting for changes before restart

Nodemon will now execute the program (because --nodejs has a flag), but when you then edit test.coffee to say console.log "Changed!" no action is taken (aka: the app isn't restarted as expected.)

@remy
Owner

Hi @ElliotChong thank you so much for the detailed reporting. I'm looking at this this w/e and this week to get cofffeescript working correctly.

I've been working on a refactor of nodemon for quite a while now and it's close to done, but I know nodemon is used is so many ways (and I'm not actually a coffeescript user in the first place) - so your kind of feedback is super super valuable.

@ElliotChong

@remy My pleasure! Honestly, thank you so much for creating and maintaining Nodemon! It's a useful part of my development workflow and it's very kind of you to support use cases outside of your own. :)

If I can help with anything else please don't hesitate to ask.

@ChrisWren ChrisWren referenced this issue in ChrisWren/grunt-nodemon Nov 30, 2013
Closed

Problems with > 0.0.09 #25

@remy
Owner

@ElliotChong can you try nodemon@dev 0.9.10 - It seems to be working fine on my machine now that I'm looking at this, but I'm not convinced that I've "accidently" fixed this.

@ElliotChong

@remy Still seeing the --nodejs argument being added in and causing problems.

Elliots-MacBook-Pro-2:PurpleLoot elliot$ nodemon web.coffee
3 Dec 10:17:53 - [nodemon] v0.9.10
3 Dec 10:17:53 - [nodemon] to restart at any time, enter `rs`
3 Dec 10:17:53 - [nodemon] watching: /Users/elliot/Dropbox/Sites/PurpleLoot
3 Dec 10:17:53 - [nodemon] starting `coffee --nodejs web.coffee`

/Users/elliot/Dropbox/Sites/PurpleLoot/web.coffee:3
# # PurpleLoot web
^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3
3 Dec 10:17:53 - [nodemon] app crashed - waiting for file changes before starting...
@remy
Owner
@ElliotChong

It's content independent, the hint here is 3 Dec 10:17:53 - [nodemon] starting `coffee --nodejs web.coffee`

Because --nodejs isn't being followed with a valid parameter (i.e.: coffee --nodejs --debug-brk web.coffee it's causing coffee to error out.

Try doing coffee --nodejs test.coffee and you'll see it blow up with a file as simple as console.log "Foo"
Executing nodemon test.coffee will result in the same error.

Nodemon should be executing: coffee test.coffee

@remy
Owner

@ElliotChong I suspect it might be that I'm on an uber old version of CoffeeScript. I've got 1.6.2 - what version are you running.

@remy
Owner

@ElliotChong right - I'm able to reproduce now (upgraded to 1.6.3 - not sure if it made a difference, but I get the bug now). To confirm, do I only need the --nodejs flag if I'm using --debug et al?

@remy
Owner

This fix has been pushed to nodemon@dev 0.9.11

@ElliotChong

Perfect! Thanks @remy!

So as a heads up, the original issue is still applicable:
run nodemon --debug test.coffee and re-save test.coffee to trigger a change, you'll then see Failed to open socket on port 5858, waiting 1000 ms before retrying because the original node process didn't release the port, resulting in a EADDRINUSE.

To quote the original post:

The problem is that when you run coffee with the --debug option, coffee spawns an extra node process that attaches itself to port 5858 for debugger. This is different from just running node --debug on a js file. So there are 2 processes that need to be killed when running coffee --debug. Since nodemon only kills one of them, when it restarts, it tries to recreate both process, but the old process is still holding on to port 5858 so it crashes.

I think the right approach is to kill the entire process tree, similar to what you are doing on windows. I'll submit a pull request for this.

@remy remy closed this in 9853e08 Dec 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment