I tried to run the sample tcp server application in http://www.haskell.org/haskellwiki/Simple_Servers this address in my GHCi for Windows. When i run 'main' function it works and client can connect. But i want to break it and hit CTRL-C but it doesn't break. How can i break the running application in GHCi?
Related
I'm trying to track down the source of an error in a Node application that doesn't come with a stack trace.
The node inspect debugger supports a breakOnException command that I think will help me.
But my application needs to take input from standard input before it produces the error I am looking for, and node inspect seems to leave my standard input going to a persistent debug> prompt even afrer I continue, when the application being debugged is running and not paused. This is unlike gdb, where when you continue the debugger prompt goes away and you need to pause the application with Ctrl+C to get it back.
How do I make node inspect's prompt go away so I can type input into the application being debugged? Alternately, if I run the application under node --inspect for remote debugging, how can I connect to a remote debugging session on the command line?
I know that a browser or an IDE like VSCode can connect to a remote NodeJS inspection session, but I can't seem to find a way to connect with the command-line debugger that is built in to node.
node inspect --help doesn't document this at all, but if you launch one Node process with node --inspect, you can attach the built-in CLI debugger using the secret -p <PID> option. Someone on Medium figured this out, and did not give a source. It's also mentioned in this answer about debugging servers.
So, start your app:
$ node --inspect whatever.js arg arg arg
Debugger listening on ws://127.0.0.1:9229/47219dfa-1b9b-40f8-92a9-0fc670bb2e0b
...
Then work out its PID:
$ pgrep -f "node --inspect"
12345
And then attach:
$ node inspect -p 12345
connecting to 127.0.0.1:9229 ... ok
debug>
I want to start debugging node.js app using Intellij and node.js interpreter running on Docker. While running the app works, when I try to debug I get the error:
Error running 'index.js'
com.github.dockerjava.api.exception.InternalServerErrorException:
{"message":"driver failed programming external connectivity on
endpoint focused_poincare
(a17137973880d1be7c6a74fc142184fdda31e0dec8ebd539b09d9dbe4cf70014):
Error starting userland proxy: Bind for 0.0.0.0:55578 failed: port is
already allocated"}
Remote interpreter was configured acccording to the documentation. I have created a new Node.js Run/Debug configuration and entered the following data:
.
What might be the cause for debugging not working?
I use:
Intellij Idea Ultimate v. 2019.1.4 Preview
Intellij NodeJS plugin v. 191.7479.1, NodeJS remote interpreter plugin v. 191.6014.8 and Docker plugin v. 191.7141.44
Docker Desktop Community v. 2.0.0.3
EDIT: Adressing the comments:
Local debugging works. The file (index.js) that I am trying to run consists only of console.log('Hello world!') so I don't spawn any child processes on my own. My host system has Windows 10 Pro as OS, so for checking the open ports on host system I used netstat -an | find "55578", which returned nothing. Moreover, if I try to run docker manually from the command line, using docker run -it -p 55578:55578 node, everything runs and no error is given.
Also, each time I try remote debugging, the port number given by Intellij in an error message seems to be random high port number. I tried looking for open ports just after getting error message, but never found one that is open with a number reported by Intellij and those indeed appear in the output:
My Run/Debug configuration:
My Docker configuration (I had to check "Expose daemon on tcp://localhost:2375 without TLS" in Docker configuration to make Intellij and Docker play together):
EDIT: When I add --inspect-brk=0.0.0.0:55432 as "Node Parameters" in "Run/Debug Configurations" Intellij windows (per this bug report) the container nad program start, but debugging seems to be no-op (e.g. the program does not stop on breakpoints).
After updating to Intellij v. 2019.2 I was able to get the container debugging to work using the workaround already mentioned in my question.
I have added a parameter --inspect-brk=0.0.0.0:55432 to Node parameters option in Run/Debug configuration (see the picture below) and everything seems to be working, including the breakpoints.
I am following the directions here: https://github.com/node-inspector/node-inspector
Pretty simple. npm install node-inspector. In one shell run node-inspector and in another run node --debug app.js. Shell spits out an localhost address with specific port for the debugger. Open that address in a browser — it loads your code. From there add breakpoints, debug network, etc..
But this does not work.
The following message endlessly logs in my shell:
Failed to open socket on port 5858, waiting 1000 ms before retrying
..and no connection is made.
So my question is has anyone had this problem and successfully found a solution. Would love to get this working, would be super useful. My only experience in server-side debuggers is Ruby's Byebug which was a piece of cake to set up.
The message you see is printed because there is another process listening on port 5858. Either a different application, or simply another instance of a node process under the debugger.
An update based on comments below this answer
If your application is running in a cluster mode via Node.js core module "cluster", then you end up with multiple worker processes, where each of them is trying to listen on port 5858.
Node Inspector cannot debug multiple worker processes at the same time. You have to pick one process and enable the debugger in that process only. When you start the app via node --debug, all processes try to enable the debugger, therefore you cannot use this command.
Instead, you have to:
Start your app without the debugger enabled.
Then you need to find the pid (process id) of the worker process you would like to debug.
Once you have the PID, you need to enable the debugger in the target process. You can run kill -1 <pid> on UNIX, or use node debug -p <pid> that works on all platforms. Don't forget to exit node debug before proceeding further.
Once the target process has debugger listening on 5858, you can start Node Inspector the usual way.
My answer is based on the following blog post: https://strongloop.com/strongblog/whats-new-nodejs-v0-12-debugging-clusters/, check it out for more details.
I am trying to debug a very simple script using "node-inspector".
I tried both following instructions on the repo, which include running "node-debug" and instructions here which include running "node --debug-brk yourApp.js".
The main problem is that neither of the commands "node", "node-debug" or "node-inspector" return any result. They just return silently.
Running "nodejs --debug-brk myScript.js" on the other hand works, but does not seem to have a nice debug GUI. I can connect to it on http://127.0.0.1:5858/ but it is hardly useful for variable inspection.
Once you've installed node-inspector globally (with npm install -g node-inspector) you can use it to connect to a nodejs process that's been run in debug mode. Try the following steps.
Open two terminal windows
In the first, run your process you'd like to debug with node --debug-brk myscript.js
In the second, run node inspector with node-inspector
In Chrome, visit the following address: http://localhost:8080/debug?port=5858
What you've done here is start node in debug mode (at port 5858 by default), then launch node inspector, which runs its own webserver on port 8080. The URL (the debug?port=5858 part) is telling node-inspector to connect to the node debug process that's on port 5858. Once you're in there, you'll see that your process has stopped on the first line (as instructed to by --debug-brk). You can then set any other breakpoints you'd like, then press the "play" button to start your process running!
This is probably a simple question but I can't find a clear answer anywhere. I am trying Hello World on node.js. I have a node.js server running on port 8000 of the localhost, turned on via the command line e.g. "node helloworld.js". Helloworld.js runs fine via localhost:8000. Now when I try turn on another server on port 8000 though I get the error "listen EADDRINUSE" because the first server is still running. So how do I turn off the first node server?
Just kill the process by doing ctrl-c...
If you still have the original terminal in which you run the Nodejs server, then simply press ctrl + C can kill the process.
However, if you lost the terminal, then you can open another terminal and run taskkill /F /IM node.exe. (/F to force the kill, /IM to specify which script you want to kill). Note that the command would kill every node server running.
If you no longer have access to your terminal, then go to your task manager on Windows or 'Force Quit' on Mac and end the 'Node.Js...' process.
This is the cleanest way to do it (if no terminal window), in my opinion.