How to turn off debugging?
- Node.js Version: v8.1.4
- OS: any
- Scope (install, code, runtime, meta, other?): runtime
- Module (and version) (if relevant): debugging
Hello,
On this page debugging-getting-started
it is mentioned that:
can also be instructed to start listening for debugging messages by signaling it with SIGUSR1 (on Linux and OS X). As of Node 7 this activates the legacy Debugger API; in Node 8 and later it will activate the Inspector API.
How to do the opposite please? That is, to disable the debugging port and the inspector protocol?
Our intention is to revert back to the previous state before debugging is enabled after a temporary debugging session, so we don't have to worry about any performance implications due to debugging being enabled.
I got a reply from https://github.com/nodejs/node/issues/15480, so this is more like a follow-up question:
how can I interact with the 'inspector' module externally?
const inspector = require('inspector');
the example seems to show a usage from within the running application itself. Is it possible to interact with the inspector protocol and close it in a out-of-process way? (which is similar to sending a SIGUSR1 signal.)
No, there is currently no support for disabling the inspector from outside the process.
@eugeneo Is it possible to disable the inspector from inside the process?
Maybe we can evaluate some require('inspector').disable() using the inspector process/debugger protocol, and have it disable the inspector and then disconnect the debugging port?
@digeff require('inspector').close() should work.
Excellent. Thanks!
I can reopen if you have any further questions.
Calling require('inspector').close() seems to result in the Node.js process finishing in some scenarios.
In Windows 10 if I run: node --inspect -e "var i =0; setInterval(function () { console.log('foo ' + i++)}, 1000)"
And I inspect the node process from Chrome with: chrome://inspect
And then I run this on the Chrome debug console: require('inspector').close();
Then the Node.js process finishes the execution.
Surprisingly if I follow the same steps, but I run: setTimeout(function () { require('inspector').close(); }, 0); instead, then the Node.js process continues running...
I tried using setTimeout(function () { require('inspector').close(); }, 0); in a connection from inside our program that uses the CRDP protocol, and the Node.js program seems to exist when we use it there.
Is this behavior expected? Is there any 100% deterministic way to stop the debugger, without stopping the Node.js program from either inside or outside the Node.js process?
Thanks!
@digeff
Are you doing that (setTimeout(function () { require('inspector').close(); }, 0)) while the Node is "Waiting for the debugger to disconnect..."?
I'm testing this with node v8.2.1
If you mean while doing this from Chrome, this is what I see on those two scenarios: setTimeout screen when done from Chrome:
node --inspect -e "var i =0; setInterval(function () { console.log('foo ' + i++)}, 1000)" Debugger listening on ws://127.0.0.1:9229/a1455c35-39a7-4de6-ab9c-e1bb1087669f For help see https://nodejs.org/en/docs/inspector foo 0 foo 1 foo 2 foo 3 Debugger attached. foo 4 foo 5 foo 6 foo 7 foo 8 foo 9 < Here I run setTimeout(function () { require('inspector').close(); }, 0) > foo 10 foo 11 < Program continues >
without setTimeout screen when done from Chrome: C:\Users\digeff>node --inspect -e "var i =0; setInterval(function () { console.log('foo ' + i++)}, 1000)" Debugger listening on ws://127.0.0.1:9229/43970dc8-6b0f-42f0-b79c-492061ad6527 For help see https://nodejs.org/en/docs/inspector foo 0 foo 1 foo 2 foo 3 Debugger attached. foo 4 foo 5 foo 6 foo 7 foo 8 foo 9 foo 10 foo 11 foo 12 foo 13 foo 14 foo 15 < Here I run require('inspector').close(); > < The program ends immediately without any additional messages >
Another issue we are running while trying to do this is, that we get this exception while trying to run: require('inspector').close(); in some scenarios:
ReferenceError: require is not defined\n at
Any idea why do we get that, and how to make this work? (Apart from the fact that it sometimes kills the process, using this from Chrome seems to work and not get this error [unless the reason that the program stop is because chrome is getting that error, I've no idea how to verify that]...)
Thanks!
The ReferenceError seems to be working on newer versions of Node.
npx nx serve api --inspect=false
TERM=dumb node to disable the inspector in interactive mode