jcollum jcollum - 1 year ago 273
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:


  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
    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
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download