Pressing play on my grunt task works, but Debugging as a address conflict

I have a set of grunt tasks, which start a web server and a set of jasmine testcases via protractor + Selenium...

  connect: {
    options: {
      port: 9000,
      hostname
: 'localhost'
    
},
    livereload
: {
      options: {
        livereload: 35729,
        open
: true,
        base
: ['www']
        
      }
    },
    test
: {
      options: {
        base: ['www']
      }
    }
  }

});
...
  
grunt.registerTask('e2e-test', ['connect:test',  'protractor:e2e', 'watch:protractor']);


The problem is, when I select to run the grunt test in debug mode.. I'm getting an error as if it's already running

/usr/local/bin/node --debug-brk=57906 /usr/local/lib/node_modules/grunt-cli/bin/grunt --gruntfile /Users/project/Gruntfile.js e2e-test

Debugger listening on port 57906

Running "connect:test" (connect) task

Started connect web server on http://localhost:9000


Running "protractor:e2e" (protractor) task

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

Should I switch to another port?  Is the debugger using 9000?

9 comments

problem may be caused by the way Grunt spawns child tasks. By default, the  spawned child process uses the same debug port as a parent process.
Please try adding 'process.execArgv = [];' to the top of  gruntfile.js - does it help?

0

Adding process.execArgv = []; to the top of the gruntfile allows the process to complete without a debugging conflict, but will not stop at any breakpoints or allow any actual debugging. It essentially acts like a run task at that point.

I also tried removing the old node --debug-brk and adding one for the grunt task using a solution I saw suggested, but this did not work. It removes the debug-brk, adds a new one, then immediately bombs out without running a test.

process.execArgv = process.execArgv.filter(function(o) {
    'use strict';
    var x = '--debug-brk';
    return o.substring(0, x.length) !== x;
});
process.execArgv.push('--debug-brk=9999');

Adding this to the Gruntfile.js results in an obscure failure:

/usr/local/bin/node --debug-brk=52581 --nolazy /usr/local/lib/node_modules/grunt-cli/bin/grunt --gruntfile /Users/csavio/edap-integrations/Gruntfile.js protractor --spec=nonamd.spec
Debugger listening on port 52581
Running "protractor:test" (protractor) task
Debugger listening on port 9999
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://127.0.0.1:49893/wd/hub
>> Debugger listening on port 9999
Warning: Tests failed, protractor exited with code: null
0

Please try using Node.js Run configuration instead of Grunt configuration for debugging:


Working directory: <project root dir>
JavaScript file: /path/to/grunt-cli/bin/grunt
Application parameters: protractor etc.

It's not possible to debug child processes using Grunt run configuration, see https://youtrack.jetbrains.com/issue/WEB-16786

0

Similar results.

/usr/local/bin/node --debug-brk=50500 --nolazy /usr/local/lib/node_modules/grunt-cli/bin/grunt ptor --spec=amd.spec
Debugger listening on port 50500
Running "ptor" task

Running "clean:build" (clean) task
>> 1 path cleaned.

Running "clean:stage" (clean) task
>> 1 path cleaned.

Running "replace:version" (replace) task

Running "replace:config" (replace) task

Running "cleanup-src-paths" task

Running "requirejs:minified" (requirejs) task

Running "requirejs:raw" (requirejs) task

Running "protractor:test" (protractor) task
Error: listen EADDRINUSE :::50500
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Agent.Server._listen2 (net.js:1237:14)
at listen (net.js:1273:10)
at Agent.Server.listen (net.js:1369:5)
at Object.start (_debug_agent.js:21:9)
at startup (node.js:102:9)
at node.js:1000:3
0
Did you add process.execArgv = [] to your gruntfile? problem spawning child processes
is not specific to run configuration being used, you still need to make sure that child
process is using a different debug port
0

Similarly adding process.execArgv = []; to the top of the gruntfile allows the process to complete without a debugging conflict, but will not stop at any breakpoints or allow any actual debugging. It essentially acts like a run task at that point.

node -v
v4.3.0

grunt --version
grunt-cli v0.1.13
grunt v0.4.5
0

Actually this allows me to debug the grunt task, but not the child process. I misspoke. I could also do that with a grunt debug configuration as well and didn't realize it because that wasn't what I was trying to debug.

0

Seems the problem is that the child process (protractor) is spawned without '--debug' option, and thus debugger can't attach to it: by default, grunt.util.spawn() inherits process arguments and starts child process with same options as the main process, causing EADDRINUSE; adding 'process.execArgv = []' helps to proceed with process execution, but now process.execArgv is empty, and child process is started without debug option. So, you have to modify the task runner accordingly.... For example, if you are using 'grunt-protractor-runner', you have to modify grunt-protractor-runner\tasks\protractor_runner.js. For example, by adding

args.unshift('--debug-brk=6666');

after
var args = process.execArgv.concat(cmd);

 

 

 

0

Please sign in to leave a comment.