balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

"sails debug" on node v0.12.0 throwing error EADDRINUSE #2670

Closed MikeCostello closed 9 years ago

MikeCostello commented 9 years ago

Running Sails v0.11.0 and Node v0.12.0

When I run

sails new app; cd app
sails debug

Console logs...

error: Grunt :: Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Agent.Server._listen2 (net.js:1129:14)
    at listen (net.js:1155:10)
    at Agent.Server.listen (net.js:1240:5)
    at Object.start (_debugger_agent.js:20:9)
    at startup (node.js:86:9)
    at node.js:814:3

No conflicting ports were listening prior to running sails. Looking at travis.yml is only node v0.10.x supported currently?

Kikobeats commented 9 years ago

at this moment sails pass the tests for 0.10.x, so I think that is not possible run your code under 0.12 because is not officially supported...

(Although I do not think that error is the version of node).

tjwebb commented 9 years ago

error: Grunt :: Error: listen EADDRINUSE

There's only one way this happens. It's if your port is already being used by another program.

MikeCostello commented 9 years ago

Agreed, but this is the output just prior to launching sails debug

lsof -i -P | grep -i "listen"

redis-ser  678 mikecostello    4u  IPv6 0x704352d066f66a57      0t0  TCP *:6379 (LISTEN)
redis-ser  678 mikecostello    5u  IPv4 0x704352d06e87f7d7      0t0  TCP *:6379 (LISTEN)
postgres  1604 mikecostello    5u  IPv6 0x704352d066f68357      0t0  TCP localhost:5432 (LISTEN)
postgres  1604 mikecostello    6u  IPv4 0x704352d07074ad67      0t0  TCP localhost:5432 (LISTEN)
postgres  1604 mikecostello    7u  IPv6 0x704352d066f66f57      0t0  TCP localhost:5432 (LISTEN)
GitHub    8261 mikecostello   15u  IPv4 0x704352d07dc24d67      0t0  TCP localhost:25035 (LISTEN)
GitHub    8261 mikecostello   16u  IPv6 0x704352d066f67957      0t0  TCP localhost:25035 (LISTEN)

After running sails debug the debug port is opened and I can connect with node-inspector. Just the error is logged in the console.

Node v0.10 & Sails v0.11 works Node v0.12 & Sails v0.10.5 same error

tjwebb commented 9 years ago

Hmm. It's also not clear to me why the error appears to come from Grunt, and not the debugger. Can you disable Grunt and try again?

MikeCostello commented 9 years ago

With Grunt disabled no error

wewoor commented 9 years ago

I have the same problem, how to solve it... console will output Error: listen EADDRINUSE When i'm run

node-debug app.js

,And the Node Inspector not work correctly.

My node version:v0.12.0 sails: v0.10.5

it's too bad not this tool.

Patrick64 commented 9 years ago

I'm getting the same, it prevents assets from copying to .tmp/public. I've tried changing the ports as follows but it's still giving the error. node-debug --debug-port=3333 --web-port=4444 app.js

nicco commented 9 years ago

Sails 0.11:

node 0.10 -> works node 0.11 -> EADDRINSUSE node 0.12 -> EADDRINSUSE

konstantinzolotarev commented 9 years ago

+1 for this issue.

nehalmehta commented 9 years ago

Same issue when running Sails v0.11.0 and Node v0.12.0

As nicco has mentioned it works in Node V0.10.0

salmankhann commented 9 years ago

I seem to have the same problem... Anyone found a fix yet?

nicco commented 9 years ago

Node 0.10.x Is the only option

On Wed, Mar 18, 2015, 17:56 chemjournal notifications@github.com wrote:

I seem to have the same problem... Anyone found a fix yet?

— Reply to this email directly or view it on GitHub https://github.com/balderdashy/sails/issues/2670#issuecomment-83056689.

MikeCostello commented 9 years ago

@tjwebb comment disabling grunt avoids the error if your project doesn't need that hook.

http://sailsjs.org/#!/documentation/anatomy/myApp/sailsrc.html

{
 "hooks": {
    "grunt": false
  }
}
DrMoriarty commented 9 years ago

+1 for this issue.

node --version v0.12.0

sails --version 0.10.0-rc8

bmwertman commented 9 years ago

Any new info on this? I am getting the same error.

node --version v0.12.0

sails --version 0.11.0

Perhaps unrelated I'm also seeing an error in the node-inspector console;

Error: Cannot find module '/Users/Brad/.npm-packages/lib/node_modules/node-inspector/node_modules/v8-debug/build/debug/v0.4.2/node-v14-darwin-x64/debug.node'

bmwertman commented 9 years ago

npm cache clean and npm install node-inspector as mentioned here fixed the "cannot find module" error. But I'm still seeing the EADDRINUSE error as everyone else.

willSonic commented 9 years ago

I am using Gulp, using sails-generator and I am getting the same error.. error: Gulp :: Error: listen EADDRINUSE at exports._errnoException (util.js:746:11) at Agent.Server._listen2 (net.js:1129:14) at listen (net.js:1155:10) at Agent.Server.listen (net.js:1240:5) at Object.start (_debugger_agent.js:20:9) at startup (node.js:86:9) at node.js:814:3

tjwebb commented 9 years ago

can someone share a project I can clone to see this in action? I cannot reproduce this

WillStreeter commented 9 years ago

So I pushed this to a repository even though it is not a fully functional site...

https://github.com/WillStreeter/ang-sails-gulp

error: Gulp :: Error: listen EADDRINUSE at exports._errnoException (util.js:746:11) at Agent.Server._listen2 (net.js:1129:14) at listen (net.js:1155:10) at Agent.Server.listen (net.js:1240:5) at Object.start (_debugger_agent.js:20:9) at startup (node.js:86:9) at node.js:814:3

I am starting Sails from WebStorm and before it loads I see the above error.

I am using

--$ node -v v0.12.0 --r$ sails -v 0.11.0

tjwebb commented 9 years ago

cloned, npm install, works great:

$ tjwebb@latitude:/.../tjwebb/workspace/ang-sails-gulp (master) $ sails lift

info: Starting app...

info: 
info:                .-..-.
info: 
info:    Sails              <|    .-..-.
info:    v0.11.0             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------' 
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `/home/tjwebb/workspace/ang-sails-gulp`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Sun Mar 22 2015 23:24:04 GMT-0400 (EDT)

debug: Environment : development
debug: Port        : 1337
debug: --------------------------------------------------------
^C
$ node -v
0.10.37
$ sails -v
0.11.0
WillStreeter commented 9 years ago

so you are using $ node -v 0.10.37

I was using node 0.12.0

tjwebb commented 9 years ago

Just tried with node 0.12.0 and iojs 1.6.1 and both work.

tjwebb commented 9 years ago

Oh I get it, sails debug doesn't work. So yea, sails debug works for me with 0.10.37 but not 0.12.

Crazy idea: maybe the newer version of node sees debug on the command-line and tries to fire up a separate debugger instance?

WillStreeter commented 9 years ago

Yes.. I was just about to reply that I think that this is the issue because when I run it from the command line with a straight ... sails lift .. no problems occur but when I run it from the IDE for debugging the error appears

tjwebb commented 9 years ago

Yea, check this out:

  1. $ nmap -sV 127.0.0.1 -p 5858 says port is closed
  2. run sails debug. errors out, but don't close
  3. $ nmap -sV 127.0.0.1 -p 5858 says the port is open, as if sails debug is working.
  4. previous nmap command causes sails debug to crash with Error: write EPIPE

So the debugger is actually running. Try running node debug app.js instead and see if that works. Looks like sails debug needs to be re-tooled.

WillStreeter commented 9 years ago

So when I run it from webstorm IDE with parameter debug... I get

/usr/local/bin/node --debug-brk=53032 --nolazy debug app.js Debugger listening on port 53032 debug> < Debugger listening on port 5858 debug> connecting to port 5858... ok debug> break in app.js:55  53 // Start server  54 sails.lift(rc('sails')); >55 })();  56  57 }); debug>

seems like the closure in app.js is getting jacked...

// Start server sails.lift(rc('sails')); })();

KSanthanam commented 9 years ago

I am running node -v 0.12.0 I get the following error Error: Cannot find module '/usr/local/lib/node_modules/node-inspector/node_modules/v8-debug/build/debug/v0.4.2/node-v14-darwin-x64/debug.node

on the console of the browser. when I run

node-debug --debug-brk --harmony --use-strict app.js

on Mac terminal I get

Node Inspector is now available from http://127.0.0.1:8080/debug?port=5858 Debugger listening on port 5858

Starting the interactive shell (REPL). Type .help for help. The module in the current directory was not loaded: Cannot find module '/Users/KK/git/DNetworksAuth'. Didn't want to start REPL? Run /usr/local/bin/node-debug . instead.

I need to run node 0.11.x or above as I am using Web framework koa which needs it.

Please help.

felipecm commented 9 years ago

+1

sirsavary commented 9 years ago

+1

JameelJiwani commented 9 years ago

+1

disharmonized commented 9 years ago

+1

dbuentello commented 9 years ago

The issue surfaces between node v0.11.14 and v0.11.15

Specifically between joyent/node@a2a3fd48934f36d94575dd33d2a2cb732f937f77 and joyent/node@d87480beb29b764ba37cd983b594ad25a406a4c7 PR: joyent/node#8476

It appears as if the bug has actually been in the codebase since v0.10.x but was undetectable due to how the Grunt process was forked:

// ./node_modules/sails/lib/hooks/grunt/index.js
var child = ChildProcess.fork(

  path.join(__dirname, 'grunt-wrapper.js'),

  [
    taskName,
    '--pathToSails='+pathToSails,

    '--gdsrc='+ pathToSails + '/node_modules'
  ],

  {
    silent: true,       // => setting to false will reveal the bug
    stdio: 'pipe'
  }
);
// Don't forget to comment out the appropriate child.std* listeners

Afterwards:

Running "watch" task
Waiting...
Failed to open socket on port 5858, waiting 1000 ms before retrying
Failed to open socket on port 5858, waiting 1000 ms before retrying
Failed to open socket on port 5858, waiting 1000 ms before retrying
Failed to open socket on port 5858, waiting 1000 ms before retrying

Possible Solution:

Looking at the options for child_process.fork, the --debug flag is being passed down to the child upon exiting the womb i.e. running sails debug :

// ./node_modules/sails/bin/sails-debug.js

// Spin up child process for Sails
Womb.spawn('node', ['--debug', pathToSails, 'lift'], {
    stdio: 'inherit'
});

setting options.execArgv to an empty array removes the flag and allows the process to continue:

// ./node_modules/sails/lib/hooks/grunt/index.js
var child = ChildProcess.fork(

  path.join(__dirname, 'grunt-wrapper.js'),

  [
    taskName,
    '--pathToSails='+pathToSails,

    '--gdsrc='+ pathToSails + '/node_modules'
  ],

  {
    silent: true,       
    stdio: 'pipe',
    execArgv: []
  }
);
disharmonized commented 9 years ago

Yep. that's worked! Thanks, @dbuentello

bmustata commented 9 years ago

Same issue in here with Sails v0.11.0 and Node v0.12.0 on Mac OS.

The fix from @dbuentello is not working for me.

/usr/local/bin/node --debug-brk=56021 --nolazy app.js
Debugger listening on port 56021
Express midleware for passport
error: Error: The hook `orm` is taking too long to load.
bmustata commented 9 years ago

Any help will be appreciated on this issue. It's hard not having interactive debugger for node.js applications.

disharmonized commented 9 years ago

@bmustata but the error EADDRINUSE has gone after fix?

dbuentello commented 9 years ago

@bmustata I dont believe are issues are related. Are you using Webstorm?

While my fix passes testing, sails debug doesn't appear to be covered. Im hesistant to submit PR and would classify this as an upstream issue as others have been affected as well (node-inspector has already updated README with info) Look like fix is on the way. If your interested in tracking issue see:

node-inspector/node-inspector#534 joyent/node#9125 iojs/io.js#877

While issues are somewhat related, the consesus is that the introduction of new debugger agent has caused many headaches. A rework is on the way.


Alternate solution:

While technically the underlying problem is unrelated as it was existent in 0.10.0, a PR could be appropriate. Would like to get input from sails team on this.

bmustata commented 9 years ago

@dbuentello Yes, the debugger it's not working on Webstorm 9 and 10.

Tks and I will monitor the issues closely!

asvsfs commented 9 years ago

+1 same issue here

dustinbolton commented 9 years ago

Applied the path by @dbuentello which fixed running "sails debug" from the command line directly. I still cannot run Node inspector with Sails by running "node-debug sails debug" as I get the same type of error which seems related:

Node Inspector is now available from http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 Debugging sails

Debugger listening on port 5858

info: Running app in debug mode... info: ( to exit, type + )

Error: listen EADDRINUSE at exports._errnoException (util.js:746:11) at Agent.Server._listen2 (net.js:1146:14) at listen (net.js:1172:10) at Agent.Server.listen (net.js:1257:5) at Object.start (_debugger_agent.js:20:9) at startup (node.js:86:9) at node.js:814:3

Node v0.12.2 Sails v0.11.1

Running "node-debug sails lift" works but of course then breakpoints and other features do not work properly as to be expected. Very frustrating since this worked better with older Node versions. Love input if anyone has any further ideas on getting this working.

dapriett commented 9 years ago

I'm having issues as well, using Intellij/Webstorm. When I try to debug I get the following:

/usr/local/bin/node --debug-brk=62497 --nolazy node_modules/sails/bin/sails.js lift

Debugger listening on port 62497

info: Starting app...

error: Error: The hook `orm` is taking too long to load.
Make sure it is triggering its `initialize()` callback, or else set `sails.config.orm._hookTimeout to a higher value (currently 20000)
    at tooLong [as _onTimeout] (/Users/dprietti/AndroidStudioProjects/hydra-respond/node_modules/sails/lib/app/private/loadHooks.js:92:21)
    at Timer.listOnTimeout (timers.js:110:15)

Process finished with exit code 1

I also tried this command

/usr/local/bin/node --debug --nolazy node_modules/sails/bin/sails.js lift I get the following...

Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Agent.Server._listen2 (net.js:1129:14)
    at listen (net.js:1155:10)
    at Agent.Server.listen (net.js:1240:5)
    at Object.start (_debugger_agent.js:20:9)
    at startup (node.js:86:9)
    at node.js:814:3
tjwebb commented 9 years ago

Yea it's a known issue. Anyone who has time to submit a PR would be greatly appreciated.

dapriett commented 9 years ago

After reading the comments from the io.js issue (https://github.com/iojs/io.js/issues/877) I was able to get debug working with Intellij.

To do so you have to install the early EAP release of Intellij (see comments of https://youtrack.jetbrains.com/issue/WEB-16256#comment=27-979926). Once installed go to Help > Find Action... > Registry and uncheck the option "js.debugger.v8.use.any.breakpoint".

This fixed it for me, and the debugger loads up real quick now.

I still get the "Error: listen EADDRINUSE" issue though, but that doesn't bother me as much as the hanging, with "The hook ... is taking too long to load."

dbuentello commented 9 years ago

PR submitted @tjwebb

tjwebb commented 9 years ago

awesome @dbuentello thanks for the PR. I'll take a look.

bmustata commented 9 years ago

Switched back to node v0.10.38 and all works Ok!

node -v
v0.10.38
npm -v
2.5.1
thomas-lee commented 9 years ago

That's fix doesn't work..

node -v
v0.12.2
sails -v
0.11.0
aabluedragon commented 9 years ago

+1 having the same issue on node 0.12, works fine on 0.10

SlowburnAZ commented 9 years ago

Please fix this... do we really have to use a version of node that is 2 versions behind the latest?

tjwebb commented 9 years ago

@SlowburnAZ if you'd like to contribute to the PR for resolving this issue, that'd be much appreciated: https://github.com/balderdashy/sails/pull/2888. The core team cannot implement every fix and feature ourselves, we rely on the community to collaborate with us. Thanks.