jcollum jcollum - 1 month ago 23
Node.js Question

Is there a way to get chrome-devtools (--inspect) to automatically detach from a process that has ended?

The process, as it is:


  1. start code with --debug --inspect:

    "debug": "node --max-old-space-size=8192 --debug=5567 --inspect dist/index.js",

  2. Open devtools with url provided, something like:

    chrome-devtools://devtools/remote/serve_file/@62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node

  3. Do some debugging.

  4. Realize you have a bug, kill process (Ctrl-C) and make code changes.

  5. Restart.

  6. Start fails:
    Unable to open devtools socket: address already in use

  7. Realize that you have to manually refresh the
    chrome-devtools
    page to get it to realize the process is no longer available.



Node inspector was much better about this. Is there something I'm missing? Some flag that will make the
chrome-devtools
automatically detach from a process that has stopped?

$ versions
npm 3.10.3
node v6.7.0
OS Darwin 15.6.0 Darwin Kernel Version 15.6.0

Answer

I don't have that problem, chrome-devtools shows me a message that the debugging connection was closed when I Ctrl-C the node process.

What system are you running on? Maybe that's something that's been fixed in a newer Node or Chrome version? Or maybe you have something in your Node app that prevents proper shutdown of the socket. Can you try with a simple script instead?

jcollum here (user835611 should get the answer credit, since they tipped me off):

I had two listeners for the process termination signals:

process.on('SIGINT', function() {
  logger.warn('SIGINT received. Shutting down.');
  return process.exit(0);
});

process.on('SIGTERM', function() {
  logger.warn('SIGTERM received. Shutting down.');
  return process.exit(0);
});

Turns out those were blocking chrome's dev tools from seeing the shutdown. I don't know how that would work but that's what I observed. Commenting out process.exit made no change. How odd, it seems that having a listener on the SIGTERM / INT events blocks Chrome's dev tools from seeing that the process has exited. Never seen a side effect like that from an event listener.

Comments