help icon indicating copy to clipboard operation
help copied to clipboard

How does one pause a running process attached to with `node inspect`?

Open extradosages opened this issue 2 years ago • 3 comments

Details

I have a process running which has stalled on a remote machine and by far the easiest way to access it is using the cli debugger, node inspect -p <pid>. I've been able to attach to the process without an issue, but I would like to know how to pause the process!

I can confirm that it is not paused, because attempting to run list complains about the process not being paused. I would set a breakpoint, but I don't know where the process has stalled because I can't use list. A nice catch 22.

Node.js version

14.17.1

Example code

No response

Operating system

ubuntu bullseye

Scope

debugging

Module and version

Not applicable.

extradosages avatar Jun 30 '22 17:06 extradosages

You can use the devtools protocol and inspector module to set breakpoints. It uses a websocket to connect to the process (with remote debugging) and you can tell it to pause, break where it is or pause on uncaught exceptions - e.g. https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#method-pause - note this breaks the JavaScript part you can always connect to Node with something like lldb and debug the native bits too

benjamingr avatar Jul 05 '22 16:07 benjamingr

I'm unable to use the devtools protocol to connect to this process, which runs on a remote server and is only accessible through a web-hosted terminal.

Using inspector to set breakpoints is a good suggestion, except that I don't know where the process has stalled because I can't use list.

extradosages avatar Jul 07 '22 18:07 extradosages

I'm unable to use the devtools protocol to connect to this process, which runs on a remote server and is only accessible through a web-hosted terminal.

You can open the inspector locally on that computer and connect to it through a second node process on the same machine using the interface you have (web-hosted terminal)

benjamingr avatar Jul 08 '22 08:07 benjamingr