1

I use git bash on Windows to run commands.

In the doc on debugging they say the following:

If a process was started without --inspect, signal it with SIGUSR1 to activate the debugger and print the connection URL.

I tried to do that:

$ node index.js
server is listening on 3000

$ ps
      PID    COMMAND
    16348   /c/Program Files/nodejs/node

$ kill -s SIGUSR1 16348

But then the process stops instead of printing the connection URL:

$ node index.js
server is listening on 3000
User defined signal 1
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • Which version of Node are you using? I tested with v6 and v8, and in both cases the debugger is started (although I'm using macOS and it looks like you're using Windows). – robertklep Aug 31 '17 at 07:57
  • @robertklep, thanks, I'm using V8. Yeah, I'm on windows through git bash. Can you show the commands you executed? – Max Koretskyi Aug 31 '17 at 08:00
  • I'm using the exact same commands as you are, but it looks like SIGUSR1 only works on UNIX. There seems to be an undocumented command available to start the debugger on Windows: `node -e "process._debugProcess(PID)"` (where `PID` is the process id of the process that you want to start the debugger for). See this question: https://stackoverflow.com/questions/35735020/how-to-debug-javascript-in-nodejs-on-windows-when-im-not-the-caller-of-node-exe – robertklep Aug 31 '17 at 08:04
  • take a look if https://stackoverflow.com/questions/45882341/start-debug-session-on-running-node-app-and-attach-node-debugger/45882405#45882405 helps – Alex Blex Aug 31 '17 at 08:07
  • @AlexBlex the issue isn't sending the (correct) signal, the process exits telling it received _"User defined signal 1"_ (aka `SIGUSR1`). The problem is that the debugger isn't getting started, contrary to what the documentation states (and what actually happens on a UNIX-like OS). – robertklep Aug 31 '17 at 08:10
  • @robertklep, yeah, probably it's Windows thing. Thanks. I use `node --inspect` to start with a debugger, but it could be great to activate debugger ad hoc via the signal. Still useful knowledge. Good luck! – Max Koretskyi Aug 31 '17 at 08:12
  • Ah, missed the windows thing. afaik there are no unix signals there, but you can try `node -e "process._debugProcess(PID);"` which should trigger debug mode on the target process. – Alex Blex Aug 31 '17 at 12:54
  • @AlexBlex, thanks, how is this supposed to be used? I ran node process first, then used this process ID instead of `PID` here `node -e "process._debugProcess(12432);"`. I got an error `[eval]:1 process._debugProcess(12432);` with the pointer on `._debug...` – Max Koretskyi Aug 31 '17 at 13:03
  • interesting, what the error says? and which version of node? It is definitely there in 7.x branch https://github.com/nodejs/node/blob/v7.x/src/node.cc#L3343 – Alex Blex Aug 31 '17 at 13:11
  • @AlexBlex, v8, see [here](http://imgur.com/a/NlH4i) – Max Koretskyi Aug 31 '17 at 13:14
  • Yeah, I get it from the comments. I asked about minor version. Just tested it with v8.4.0. Didn't use bash tho. Are you sure you own the process you are going to debug? – Alex Blex Aug 31 '17 at 13:34
  • Actually the minor version doesn't matter. The error comes from windows. – Alex Blex Aug 31 '17 at 13:42
  • @AlexBlex, thanks, it's good to have a confirmation. I [tweeted](https://twitter.com/mscdexdotexe/status/903207962218569728) to V8 team about the issue – Max Koretskyi Aug 31 '17 at 13:47

1 Answers1

3

Windows does not support sending signals, but Node.js offers some emulation. Unfortunately, it does not extend to SIGUSR1.

The linked documentation in the original question has been updated to specify that SIGUSR1 only works on Linux and OS X. (Although I'm opening a pull request right now to change it to say that it doesn't work on Windows, rather than that it does work on Linux and OS X. I'm pretty sure it will work, for example, in AIX and SmartOS. There's probably even a test for it in the code base.)

Trott
  • 66,479
  • 23
  • 173
  • 212