none
[Node.js ][Web Apps] Node.js app with child_process fork() call failes with Error: listen EADDRINUSE RRS feed

  • Question

  • Debugger listening on port 5858
    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

    I have two files, the app.js file, and the code that the forked process will be running in sub.js. I copied this direcly from the official Node.js documentation - https://nodejs.org/api/child_process.html#child_process_child_send_message_sendhandle_callback

    // app.js
    var cp = require('child_process');

    var n = cp.fork(__dirname + '/sub.js');

    n.on('message', function(m) {
      console.log('PARENT got message:', m);
    });

    n.send({ hello: 'world' });

    // sub.js
    process.on('message', function(m) {
      console.log('CHILD got message:', m);
    });

    process.send({ foo: 'bar' });



    Friday, October 30, 2015 8:48 PM

Answers

  • Turns out, this is a known issue. The child is inheriting all process environment, so you need to override the debug port setting as follows.

    cp.fork('./app_FORK.js', [], { execArgv: ['--debug=5859'] });

    • Marked as answer by eljamaki Tuesday, November 3, 2015 11:23 PM
    Tuesday, November 3, 2015 11:23 PM

All replies

  • I just tried this and it seems to run fine.

    Specifically, I did this:

    • Went in Kudu Console for the site
    • Created a test folder
    • Copied both files in there
    • Ran 'node app.js'


    And got the following output:

    CHILD got message: { hello: 'world' }
    PARENT got message: { foo: 'bar' }

    Can you give more details about exactly what you are trying? The error you get relates to the debugger, which is puzzling.


    • Edited by David Ebbo Saturday, October 31, 2015 4:05 PM typo
    Saturday, October 31, 2015 4:05 PM
  • Hi,

    We are looking into this and will revert to you at the earliest.

    Girish Prajwal

    Saturday, October 31, 2015 5:02 PM
  • So, as it turns out, I can run my Mocha test from the command line and it runs fine.

    From Visual Studio <Ctrl> F5 works. This only happens with F5 debug run!

    Saturday, October 31, 2015 6:16 PM
  • So you mean you are not seeing this issue on Azure Web Apps at all, but only on your local machine? Please note that this forum is for Azure Web Apps questions, which I think is the source of confusion here.

    thanks,
    David

    Saturday, October 31, 2015 6:46 PM
  • Right, I do deploy it do Azure as a Web App, but I debug it in Visual Studio before, and that is when it happens.
    Saturday, October 31, 2015 8:33 PM
  • Turns out, this is a known issue. The child is inheriting all process environment, so you need to override the debug port setting as follows.

    cp.fork('./app_FORK.js', [], { execArgv: ['--debug=5859'] });

    • Marked as answer by eljamaki Tuesday, November 3, 2015 11:23 PM
    Tuesday, November 3, 2015 11:23 PM