使用debug-brk启动Sails不会运行Grunt?

时间:2014-10-14 17:50:24

标签: javascript node.js debugging gruntjs sails.js

当我在没有调试的情况下启动sails或仅使用--debug,并包含--verbose作为应用程序参数时,它会向我显示它运行grunt的详细信息(请参阅下面的第一个日志示例)。

但是,当我使用debug-brk =运行应用程序时,它不会运行grunt。 (参见下面的第二个日志示例)。我在一个不同的论坛上发布了这个帖子,并且有人建议"很可能grunt是作为子进程生成的,使用相同的调试端口作为父应用程序...而且,由于端口已经绑定,它已被暂停和" #34 ;.证据似乎支持这一点,但我无法找到grunt模块通过sails模块中的端口的位置。

有没有人遇到过这个?我认为这是一件很平常的事情,而且我错过了一些显而易见的事情。

此致

我正在使用...... 帆0.10.5 节点0.10.29 咕噜0.4.5 grunt-cli 0.1.13

这是一个好运行的例子..没有调试或只有--debug(不是--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...

以下是--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

1 个答案:

答案 0 :(得分:1)

TL; DR - 节点子进程分叉&#34; bug&#34;让Grunt等待一个永远无法连接的调试器。

Sails使用child_process.fork()为grunt生成一个单独的进程来运行。

新进程inherits the node command line parameters of the calling process(fork的默认操作)。在你的情况下,&#34; - debug-brk&#34;。这会导致grunt的节点进程在第一行停止 - 等待调试器连接。

不幸的是,在Windows下,此侦听端口似乎是使用SO_REUSEADDR打开的。这意味着允许两个进程在同一端口上侦听!

  

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

在我的测试中,我发现所有连接只打到了第一个开始监听的进程。我永远无法连接到子Grunt进程以允许继续执行。

我听说在新版本的Node(0.15?)中,每个fork都会从base逐步获得自己的端口。但我自己还没有测试过这个。