I have inherited a node.js / Express application that is a bit messy. It gets stuck regularly and rather randomly and does not respond to any request until it is restarted.
I suspect that something inside the application is blocking and either getting stuck in a loop or making a request to an external api without using the appropriate Async methods, and never gets a response and never picks a time when the server just stops responding but doesn't crash .
Obviously, I would like to find the criminal code and fix the problem, but at the same time I would like to find a way to automatically restart the server when it stops responding.
To test the solutions locally (since I don’t know the real culprit), I created the following express route that mimics the exact behavior that I get.
app.get('/block-block-block', function (req, res){
for(;;) {}
};
The question I have is that the specified route is being routed (which immediately stops the server from answering anything), is there a way to detect the lock inside the node internally and restart or close? And if not, is this a good solution to check when the server is not responding and rebooting it?
Most of the searches I performed lead me to tools like forever and PM2 . They work great if your application crashes, but I really do not see any options for restarting when the application blocks radomies.