Websocket NodeJS Crashing - node.js

Hey there im getting this error which is crashing my program after 12h or 24h and i have to restart it is there anyway to fix this?
ERROR :
/root/Chat/node_modules/ws/lib/websocket.js:334
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
^
Error: WebSocket is not open: readyState 0 (CONNECTING)
at WebSocket.send (/root/Chat/node_modules/ws/lib/websocket.js:334:13)
at Timeout._onTimeout (/root/Chat/index.js:51:14)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
Code : https://hastebin.com/fayasobeha.js

Websockets are not a common TCP servers, They are more of 2 way connection between the Client and the Server. If you following any architecture(Micro/Mono) Make sure you check is there any other system thread going on at peak hours which is causing the crash.
It's always better if you can wrap your service in Container and run it as a separate process there.

Related

Getting Timeout errors when load increases in ioredis

We're using a NodeJS-based app using express for routing http requests. Before routing the requests we have a middleware to perform some validation using Redis, wherein we use ioredis.
When the load is moderate it works fine. But when there is an increase in load, ioredis started throwing timeout errors.
Error: Command timed out at Timeout._onTimeout (/proj/node_modules/ioredis/built/command.js:261:33) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)
[stack]: 'Error: Command timed out\n' + ' at Timeout._onTimeout (/proj/node_modules/ioredis/built/command.js:261:33)\n' at listOnTimeout (internal/timers.js:554:17)\n' + ' at processTimers (internal/timers.js:497:7)',
[message]: 'Command timed out'
Initially, we had the command timeout set as 2 seconds. It started throwing the error frequently. Post that we now changed it to 5 seconds. It was better than before, but still, we face the timeout issue when the load increases.
We didn't find any redis slowlog too. We're using a Kubernetes setup within which we use redis sentinels ( 1 master 2 slaves ) to connect to from the app.
Any help on this query would be helpful

500 Internal Server Error for URL: http://localhost:8100/api/timeline

500 Internal Server Error for URL:http://localhost:8100/api/timeline dev4living/HeyCommunity
I am trying to run a dev4living/HeyCommunity webApp on a local host but i'm getting the following error:
Error: connect EADDRINUSE 127.0.0.1:8100
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
http://localhost:8100/
-i used the lastest update dev-playing : dev4living/HeyCommunity-backend and dev4living/HeyCommunity-frontendenter code here
-What should i do to fix this error?
-Your assistance will be very much appreciated.
The error states that the port you are trying to use is already occupied. Please check the app running in the port 8100 and stop that and try to run the app again. Changing the port number to something else apart from 8100 will also solve the problem.
The error is pretty self-explanatory buddy. It just means that the address you have used, i.e, the port number is currently in use by something else.
2 possible solutions:
Simply change the port number
using cmd to get the list of processes running. Identify the process running on that port. And use taskkill -pid command. Refer this stack overflow post for details regarding this method

NodeJS ExpressJS ETIMEDOUT net.js

came in on Monday morning and my node app is not working. No code changes have occurred recently. Users are receiving this error when trying to connect:
Error: connect ETIMEDOUT
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
Seems like something must have changed on the server, although I'm yet to figure out what it is. There was a power outage over the weekend. Any insights as to what would cause this? I receive the same error if I try to connect to my node app on the server itself, so it seems it can't be firewall related.
In case it's helpful to anyone else, the problem was that my backend database services had not restarted after the power outage. Not sure why this was the error thrown, but that's what solved it for me!

Forever Crashes and Doesn't Restart after 4 times

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

Socket Hang Up on Nodejitsu, What does it mean?

I'm getting socket hang up errors on Nodejitsu, what does it mean?
error: Error running command deploy
error: socket hang up
error: Error: socket hang up
error: at createHangUpError (http.js:1107:15)
error: at Socket.onend (http.js:1188:27)
error: at TCP.onread (net.js:369:26)
info: Nodejitsu not ok
Two things that you might be doing that cause this:
Make sure you're using port > 1024 (no sudo) Make sure your app is <
50mb disk space
If this doesn't work please either email support at nodejitsu or visit #nodejitsu at irc.freenode.org

Resources