Reputation: 1605
I am working on a node.js app, and occasionally it seems to freeze. I assume this is because the user code thread has frozen. It seems to happen after about 5 minutes of usage, but I have no idea why. Are there any tools that would let you know where it's become deadlocked? Apart from adding logging on every line.
Updated to add more information....
I've added some trace statements and have narrowed it down to the following code:
exports.addLocationToRoute = function(req, res) {
console.log("27");
console.log(req.body);
var queryConfig = {
text: "INSERT INTO route_locations (route_id, location_id, order_id) VALUES ($1, $2, $3);",
values: [req.params.id, req.body.locationId, req.body.order]
};
pg.connect(conString, function(err, client) {
console.log("28");
...
I see 27 output in trace, but not 28. Is there a way to see why it is frozen between those two points?
update 2:
I just tried to reproduce again and it's become frozen at a different point in the code, but at this point it is also calling
pg.connect(conString, function(err, client) {
Upvotes: 4
Views: 2084
Reputation:
You probably want to put node into --debug
mode and analyze it with node-inspector.
When the code locks on some place, you can pause the execution with the pause-button ( http://pix.am/LYZz/ ) and inspect the stack trace to find locks.
Upvotes: 0
Reputation: 10014
I'm using JetBrains WebStorm IDE for my Javascript development. It has full Node support, meaning you can set breakpoints and trace your code. However, WebStorm isn't free. You may also look at an older topic on Node debugging: How do I debug Node.js applications?
There's an accepted answer about using Chrome Development Tools, but I'd rather followed more popular answer's way of using node-inspector for debugging.
Upvotes: 4