Ziggleflig
Ziggleflig

Reputation: 71

Starting Sails with debug-brk doesn't run Grunt?

When I launch sails without debug or with only --debug, and include --verbose as an application parameter, it shows me the details of it's run of grunt (see first log example below).

However, when I run the app with debug-brk= it does not run grunt. (See second log example below). I posted this in a different forum and someone suggested that "Most probably grunt is spawned as a child process using same debug port as a parent application... And, as the port is already bound, it's suspended". The evidence seems to support this, but I can't locate where the grunt modules are getting passed the port in the sails module.

Has anyone encountered this? I would think it'd have been a common thing and that I'm missing something obvious.

Regards

I'm using... Sails 0.10.5 Node 0.10.29 grunt 0.4.5 grunt-cli 0.1.13

Here is the example of a good run.. without debug or with only --debug (not --debug-brk)

C:\Users\myuser\git\datavis>node app.js --verbose
verbose: Setting Node environment...
verbose: Please run `npm install coffee-script` to use coffescript (skipping for now)
verbose: moduleloader hook loaded successfully.
verbose: Loading app config...
verbose: userconfig hook loaded successfully.
verbose: Exposing global variables... (you can disable this by modifying the properties in `sails.config.globa
verbose: logger hook loaded successfully.
verbose: request hook loaded successfully.
verbose: Loading the app's models and adapters...
verbose: Loading app models...
verbose: Loading app adapters...
verbose: Loading blueprint middleware...
verbose: blueprints hook loaded successfully.
verbose: Loading runtime custom response definitions...
verbose: responses hook loaded successfully.
verbose: controllers hook loaded successfully.
verbose: Loading policy modules from app...
verbose: Finished loading policy middleware logic.
verbose: policies hook loaded successfully.
verbose: Loading app services...
verbose: services hook loaded successfully.
verbose: csrf hook loaded successfully.
verbose: cors hook loaded successfully.
  i18n:debug will write to C:\Users\myuser\git\datavis\config\locales\en.json +0ms
  i18n:debug read C:\Users\myuser\git\datavis\config\locales\en.json for locale: en +1ms
  i18n:debug will write to C:\Users\myuser\git\datavis\config\locales\es.json +1ms
  i18n:debug read C:\Users\myuser\git\datavis\config\locales\es.json for locale: es +0ms
  i18n:debug will write to C:\Users\myuser\git\datavis\config\locales\fr.json +0ms
  i18n:debug read C:\Users\myuser\git\datavis\config\locales\fr.json for locale: fr +1ms
  i18n:debug will write to C:\Users\myuser\git\datavis\config\locales\de.json +0ms
  i18n:debug read C:\Users\myuser\git\datavis\config\locales\de.json for locale: de +0ms
verbose: i18n hook loaded successfully.
verbose: session hook loaded successfully.
verbose: Loading app Gruntfile...
verbose: Tracking new grunt child process...
verbose: grunt hook loaded successfully.
verbose: http hook loaded successfully.
verbose: Overriding ejs engine config with ejslocals to implement layout support...
verbose: Configuring socket (ws://) server...
verbose: sockets hook loaded successfully.
verbose: Loading user hooks...
verbose: Located 0 user hook(s)...
verbose: views hook loaded successfully.
verbose: Setting default Express view engine to ejs...
verbose: Initialized 0 user hook(s)...
verbose: userhooks hook loaded successfully.
verbose: Loading adapter ( sails-disk ) for sdm  from `node_modules` directory...
verbose: Starting ORM...
verbose: orm hook loaded successfully.
verbose: pubsub hook loaded successfully.
verbose: Built-in hooks are ready.
verbose: Instantiating registry...
verbose: Loading router...
verbose: Policy-controller bindings complete!
verbose: Waiting for all hooks to declare that they're ready...
verbose: All hooks were loaded successfully.
verbose: Starting app at C:\Users\myuser\git\datavis...
verbose: Running the setup logic in `sails.config.bootstrap(cb)`...
verbose: Restricting access to explicit host: 0.0.0.0
info:
info:
info:    Sails              <|
info:    v0.10.5             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------'
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info:
info: Server lifted in `C:\Users\myuser\git\datavis`
info: To see your app, visit http://0.0.0.0:8181
info: To shut down Sails, press <CTRL> + C at any time.

debug: --------------------------------------------------------
debug: :: Tue Oct 14 2014 09:04:11 GMT-0400 (Eastern Daylight Time)

debug: Environment : development
debug: Host        : 0.0.0.0
debug: Port        : 8181
debug: --------------------------------------------------------
verbose: Grunt :: Running "clean:dev" (clean) task
verbose: Grunt :: >> 191 paths cleaned.
verbose: Grunt :: Running "jst:dev" (jst) task
>> Destination not written because compiled files were empty.

Running "less:dev" (less) task
verbose: Grunt :: Running "copy:dev" (copy) task
verbose: Grunt :: Copied 178 files

Running "coffee:dev" (coffee) task
>> 0 files created.

Running "sails-linker:devJs" (sails-linker) task
padding length 4
File "views/layout.ejs" updated.

Running "sails-linker:devStyles" (sails-linker) task
padding length 4
File "views/layout.ejs" updated.

Running "sails-linker:devTpl" (sails-linker) task
padding length 4
File "views/layout.ejs" updated.

Running "sails-linker:devJsJade" (sails-linker) task

Running "sails-linker:devStylesJade" (sails-linker) task

Running "sails-linker:devTplJade" (sails-linker) task
verbose: Grunt :: Running "watch" task
Waiting...
verbose: Lowering sails...
verbose: Sent kill signal to child process (21060)...
verbose: Shutting down socket server...
verbose: Socket server shut down successfully.
verbose: Shutting down HTTP server...

and here is the example with --debug-brk=

C:\Program Files\nodejs\node.exe --debug-brk=53447 --nolazy app.js --verbose
debugger listening on port 53447
verbose: Setting Node environment...
verbose: Please run `npm install coffee-script` to use coffescript (skipping for now)
verbose: moduleloader hook loaded successfully.
verbose: Loading app config...
verbose: userconfig hook loaded successfully.
verbose: Exposing global variables... (you can disable this by modifying the properties in `sails.config.globals`)
verbose: logger hook loaded successfully.
verbose: request hook loaded successfully.
verbose: Loading the app's models and adapters...
verbose: Loading app models...
verbose: Loading app adapters...
verbose: Loading blueprint middleware...
verbose: blueprints hook loaded successfully.
verbose: Loading runtime custom response definitions...
verbose: responses hook loaded successfully.
verbose: controllers hook loaded successfully.
verbose: Loading policy modules from app...
verbose: Finished loading policy middleware logic.
verbose: policies hook loaded successfully.
verbose: Loading app services...
verbose: services hook loaded successfully.
verbose: csrf hook loaded successfully.
verbose: cors hook loaded successfully.
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug will write to c:\Users\cdeanhar\git\datavis\config\locales\en.json
debug: --------------------------------------------------------
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug read c:\Users\cdeanhar\git\datavis\config\locales\en.json for locale: en
debug: :: Sun Oct 12 2014 21:31:44 GMT-0400 (Eastern Daylight Time)
debug: Environment : development
debug: Host        : 0.0.0.0
debug: Port        : 8181
debug: --------------------------------------------------------
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug will write to c:\Users\cdeanhar\git\datavis\config\locales\es.json
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug read c:\Users\cdeanhar\git\datavis\config\locales\es.json for locale: es
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug will write to c:\Users\cdeanhar\git\datavis\config\locales\fr.json
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug read c:\Users\cdeanhar\git\datavis\config\locales\fr.json for locale: fr
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug will write to c:\Users\cdeanhar\git\datavis\config\locales\de.json
Mon, 13 Oct 2014 01:31:42 GMT i18n:debug read c:\Users\cdeanhar\git\datavis\config\locales\de.json for locale: de
verbose: i18n hook loaded successfully.
verbose: session hook loaded successfully.
verbose: Loading app Gruntfile...
verbose: Tracking new grunt child process...
verbose: grunt hook loaded successfully.
verbose: http hook loaded successfully.
verbose: Overriding ejs engine config with ejslocals to implement layout support...
verbose: Configuring socket (ws://) server...
verbose: sockets hook loaded successfully.
verbose: Loading user hooks...
verbose: Located 0 user hook(s)...
verbose: views hook loaded successfully.
verbose: Setting default Express view engine to ejs...
verbose: Initialized 0 user hook(s)...
verbose: userhooks hook loaded successfully.
verbose: Loading adapter ( sails-disk ) for sdm  from `node_modules` directory...
verbose: Starting ORM...
verbose: orm hook loaded successfully.
verbose: pubsub hook loaded successfully.
verbose: Built-in hooks are ready.
verbose: Instantiating registry...
verbose: Loading router...
verbose: Policy-controller bindings complete!
verbose: Waiting for all hooks to declare that they're ready...
verbose: All hooks were loaded successfully.
verbose: Starting app at c:\Users\cdeanhar\git\datavis...
verbose: Running the setup logic in `sails.config.bootstrap(cb)`...
verbose: Restricting access to explicit host: 0.0.0.0
info: 
info: 
info:    Sails              <|
info:    v0.10.4             |\
info:                       /|.\
info:                      / || \
info:                    ,'  |'  \
info:                 .-'.-==|/_--'
info:                 `--'-------' 
info:    __---___--___---___--___---___--___
info:  ____---___--___---___--___---___--___-__
info: 
info: Server lifted in `c:\Users\cdeanhar\git\datavis`
info: To see your app, visit http://0.0.0.0:8181
info: To shut down Sails, press <CTRL> + C at any time.


verbose: browser client (v0.10.0) is trying to connect a socket...
verbose: Generated new session for socket.... { headers: 
   { host: 'localhost:8181',
     connection: 'keep-alive',
     'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36',
     accept: '*/*',
     referer: 'http://localhost:8181/',
     'accept-encoding': 'gzip,deflate,sdch',
     'accept-language': 'en-US,en;q=0.8',
     cookie: 'search=ITSM; tab=0; sails.sid=s%3AIx4tfewY7LnBgXKFvlozSsyQ.qExipPSWxVgz7yG8wRgCq6h4DDgYIahIuQKTGTAAVMM; dev-perspective=App%20Owner; dev-focusME=2bc6168b249968d001249f6557760003' },
  address: { address: '127.0.0.1', port: 53462 },
  time: 'Sun Oct 12 2014 21:31:44 GMT-0400 (Eastern Daylight Time)',
  query: 
   { __sails_io_sdk_version: '0.10.0',
     __sails_io_sdk_platform: 'browser',
     __sails_io_sdk_language: 'javascript',
     t: '1413163902883' },
  url: '/socket.io/1/?__sails_io_sdk_version=0.10.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&t=1413163902883',
  xdomain: false,
  secure: undefined,
  issued: 1413163904190,
  cookie: 
   { search: 'ITSM',
     tab: '0',
     'sails.sid': 's:Ix4tfewY7LnBgXKFvlozSsyQ.qExipPSWxVgz7yG8wRgCq6h4DDgYIahIuQKTGTAAVMM',
     'dev-perspective': 'App Owner',
     'dev-focusME': '2bc6168b249968d001249f6557760003' },
  sessionID: 'Ix4tfewY7LnBgXKFvlozSsyQ',
  session: { cookie: { httpOnly: true } } }
verbose: authorized
verbose: handshake authorized dS9obVLitVM6vFL4Ies8
verbose: Rendering view: "home/index" (located @ "c:\Users\cdeanhar\git\datavis\views\home\index")
verbose: • using configured layout:: layout (located @ "c:\Users\cdeanhar\git\datavis\views\layout")
verbose: Rendering view: "home/index" (located @ "c:\Users\cdeanhar\git\datavis\views\home\index")
verbose: • using configured layout:: layout (located @ "c:\Users\cdeanhar\git\datavis\views\layout")
verbose: browser client (v0.10.0) is trying to connect a socket...
verbose: Connected socket to existing session....
verbose: authorized
verbose: handshake authorized 1PVmZ4H7A9dDqfRzIes9
verbose: Sending 404 ("Not Found") response
verbose: setting request GET /socket.io/1/websocket/1PVmZ4H7A9dDqfRzIes9?__sails_io_sdk_version=0.10.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript
verbose: set heartbeat interval for client 1PVmZ4H7A9dDqfRzIes9
verbose: client authorized for 
verbose: websocket writing 1::
verbose: A socket.io client (1PVmZ4H7A9dDqfRzIes9) connected successfully!
Loading first.. [object Object]
Loading more.. [object Object]
verbose: Sending 404 ("Not Found") response

Upvotes: 1

Views: 618

Answers (1)

Ivan Hamilton
Ivan Hamilton

Reputation: 3265

TL;DR - A Node child process forking "bug" leaves Grunt waiting for a debugger that can never connect.

Sails uses child_process.fork() to spawn a separate process for grunt to run in.

The new process inherits the node command line parameters of the calling process (default operation of fork). In your case, "--debug-brk". This causes the node process for grunt to stop on the first line - waiting for a debugger to connect.

Unfortunately, under Windows, this listening port appears to be opened with SO_REUSEADDR. This means that two processes are allowed to listen on the same port!

"Once the second socket has successfully bound, the behavior for all sockets bound to that port is indeterminate."

In my testing, I found that all connections only hit the first process that started listening. I could never connect to the child Grunt process to allow execution to continue.

I've heard that in newer versions of Node (0.15?) every fork will get own port incrementally from base. But I haven't tested this myself.

Upvotes: 1

Related Questions