Forever Crashes and Doesn't Restart after 4 times - node.js

I have a node server running on AWS and I am using forever to keep it running in the background.
I have been very happy with forever so far; it's super easy to set up and use. However, even though my app is very simple, sometimes it crashes with this error:
Express server listening on port 3001
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
error: Forever detected script exited with code: 8
error: Forever restarting script for 4 time
When I look back at the logs, I can see that this has happened 4 more times, and each time forever manages to restart the server. However, when it happens for the 5th time, for some reason forever fails to restart the server and my app becomes unresponsive.
Express server listening on port 3001
events.js:72
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
error: Forever detected script exited with code: 8
/usr/lib/node_modules/forever/node_modules/forever-monitor/node_modules/broadway/node_modules/eventemitter2/lib/ev$
throw arguments[1]; // Unhandled 'error' event
^
Error: Cannot stop process that is not running.
at /usr/lib/node_modules/forever/node_modules/forever-monitor/lib/forever-monitor/monitor.js:332:26
at process._tickCallback (node.js:415:13)
Has anyone else experienced similar problems?

You have to use the option -MAX like this:
forever -MAX 10000000000 Mypath/ToMyFile.js
Also put a -minUptime for the minimum time the server can stay up, if it crash before that laps of time then it won't go up again so set it to 1.
forever --minUptime (number-in-milisecond-here) -MAX (number-of-restart-here) path/file.js
Just try this:
forever --minUptime 1 -MAX 1000000000 YourPath/ToYourFile.js
More documentation there
https://www.npmjs.com/package/forever

To allow a max of 100 restarts when the server crashes
forever start -m 100 index.js

Related

NodeJS Conditional Server Startup

Is there any way in node.js wherein I can start a server on a condition.
Suppose I want to load some parameters from DB into memory and if the load is successful, then only start the server else don't start.
I am a bit of a new to node.js and this seems quite a beginners question. Is it possible?
In fact, I created a conditional server start-up but I am getting the below error every time.
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3007
at Server.setupListenHandle [as _listen2] (net.js:1360:14)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
And I did a lookup for my application and it was not running at all. After that, I tried changing my port multiple times but no luck. The error seems persistent.

When running or lifting sails/nodeJS application Error: listen EADDRINUSE

events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1039:14)
at listen (net.js:1061:10)
at Server.listen (net.js:1135:5)
at Array.async.auto.start [as 0] (/var/www/html/zentiera/node_modules/sails/lib/hooks/http/start.js:29:35)
While using sails js or node js, The error may create difficulties in newbies of technology.
This specially comes when we try to stop the application using (ctrl+z)
and unfortunately the error creates while restarting it
^Z
[1]+ Stopped sails lift
There are 2 methods to recover this situation :
Need to kill the previous port
fuser -k 9002/tcp
Declare a different port number in your application
localhost//config/local.js
port: process.env.PORT || newPortNumber,

Mean.IO does not work on Redhat 6.5 VM

I am developing an application based on MEAN.IO, it works fine on my local Windows 7 machine, so I want to publish the app.
I have a remote Redhat 6.5 virtual machine (VM) server which can be used to host my application for public access. After uploading and run the app with grunt, it stops with an error:
$ grunt
Running "hook" task
Starting hooked tasks.
Running "clean:0" (clean) task
0 paths cleaned.
Running "jshint:all" (jshint) task
42 files lint free.
Running "csslint:src" (csslint) task
5 files lint free.
Running "concurrent:tasks" (concurrent) task
Running "watch" task
Waiting...
Running "nodemon:dev" (nodemon) task
[nodemon] v1.2.1
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node --debug server.js
debugger listening on port 5858
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
[nodemon] app crashed - waiting for file changes before starting...
I also tried to clone the code into the server directly from https://github.com/linnovate/mean.git, without ANY changes and run the app, but I got the same error as above.
I tried run node server.js instead of grunt, I got similar errors as below:
[jking#server eclipse_test]$ node server.js
for real!
forking 0
forking 1
forking 2
forking 3
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Worker 3 died :(
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Worker 2 died :(
...
__________________________________________________________
I don't know if it is due to the virtual machine or the mean.io stack.
Can someone give me any clue or answer to resolve it?
thanks
-John
I had the same problem and struggled all day with it until I found this:
https://forums.aws.amazon.com/thread.jspa?messageID=622248
Basically in my instance Amazon's linux image did not have the computer name associated with 127.0.0.1.
My instance was named ip-10-0-0-117 so I changed /etc/hosts from:
127.0.0.1 localhost localhost.localdomain
into
127.0.0.1 localhost localhost.localdomain ip-10-0-0-117
and everything works!

error message, node project installation on server?

Im trying to start my node project on my node server but I keep getting a error message, the server is ready to use node, I already have some other projects installed on it but this I can't understand. Can anyone understand this error message?
events.js:69
throw arguments[1]; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:850:11)
at Server._listen2 (net.js:995:14)
at listen (net.js:1022:10)
at Server.listen (net.js:1071:5)
at Function.app.listen (/srv/www/ikonset.com/node_modules/express/lib/application.js:531:24)
The error EADDRINUSE means you already have a process bound to the port you're trying to listen on (3000 or whatever). What you should do is first STOP your other process on that port, then restart your Node app.

Socket.io server not working

I've got a Socket.io server that is not working (it shows the following error on Firebug and of course it doesn't any of its functions):
GET http://www.example.com:1618/socket.io/1/?t=1401400488401 400 Bad Request 35ms
Also, when I try to run the server, it outputs that:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at net.js:1146:9
at asyncCallback (dns.js:68:16)
at Object.onanswer [as oncomplete] (dns.js:121:9)
I am running it on Ubuntu 14.04
EADDRINUSE means that there is another process that is listening to the port you're using for socket.io. Try changing the port number for socket.io when listen() is called.
On ubuntu, you might need to run it with sudo:
sudo nodejs your_server.js

Resources