Cannot connect to Mongo Server - node.js

There are no mongo server or any servers or any services running on that ip:port but we are still getting this kind of error.
(lockerdb) Database connection error: { [Error: failed to connect to [127.0.0.1:10004]]
[stack]: [Getter/Setter],
[message]: 'failed to connect to [127.0.0.1:10004]',
[arguments]: undefined,
[type]: undefined }
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'close' of null
at /home/<user>/Documents/Server_v1/ssc/ssc-lac/lac-util.js:1653:15
at /home/<user>/node_modules/mongodb/lib/mongodb/db.js:247:16
at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/server.js:383:7)
at [object Object].emit (events.js:88:20)
at [object Object].<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:93:15)
at [object Object].emit (events.js:70:17)
at Socket.<anonymous> (/home/<user>/node_modules/mongodb/lib/mongodb/connection/connection.js:385:10)
at Socket.emit (events.js:67:17)
at Array.0 (net.js:319:25)
at EventEmitter._tickCallback (node.js:192:41)
What could be the cause of this error?

You are most likely still trying to connect to a service on that port.
The default behaviour is to attempt to connect and when it can't it dies with an error like the one you see. This is for saftey reasons since a connection error 90% of the time means a downed DB (like it does in your case) which is bad and shouldn't be ignored.
The easiest way to overcome this error is to try catch the connection block so as to understand when a connection error has been received and do something about it.

Related

Redis connection to x.x.x.x:6379 failed - write ECONNRESET. NodeJS GCP Standard Environment

The redis get calls sometimes fails with the following error. Once this happens, as a follow through, many of the requests fail/timeout intermittently with a 502 status.
{ Error: Redis connection to X.X.X.X:6379 failed - write ECONNRESET
at afterWriteDispatched (internal/stream_base_commons.js:78:25)
at writeGeneric (internal/stream_base_commons.js:73:3)
at Socket._writeGeneric (net.js:714:5)
at Socket._write (net.js:726:8)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
at Socket.Writable.write (_stream_writable.js:299:11)
at RedisClient.write (/workspace/node_modules/redis/index.js:949:43)
at RedisClient.internal_send_command (/workspace/node_modules/redis/index.js:885:14)
at RedisClient.internal_send_command_trace [as internal_send_command] (/workspace/node_modules/#google-cloud/trace-agent/build/src/plugins/plugin-redis.js:91:50)
at RedisClient.get (/workspace/node_modules/redis/lib/commands.js:46:25)
at Promise (internal/util.js:274:30)
at new Promise (<anonymous>)
at RedisClient.get (internal/util.js:273:12)
at ConversationQueueServices.startTimeoutToClearQueueForVisitor (/workspace/ls/Services/ConversationQueueServices.js:306:57)
at PeoplesService.onVisitorSubscriberLeft (/workspace/ls/Services/PeoplesService.js:51:31)
at app.post (/workspace/app.js:196:27)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at next (/workspace/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/workspace/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/workspace/node_modules/express/lib/router/layer.js:95:5)
at /workspace/node_modules/express/lib/router/index.js:281:22 errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'write' }
From the looks of it, ECONNRESET indicates the connection is closed by redis instance. There is no surge of traffic of any sort. cpu, memory and number of connections are as usual.
Will moving to updated redis npm client may help? Currently using 3.0.2 redis client version
Any help is much appreciated. Thanks in advance.
ECONNRESET error is thrown usually when the other end of the connection which could be TCP connected node that is communicating with the server or calling out and the socket timeout results in no response received which results in the sender closing it with the timeout exception handling type.
You can try to add retries or increase the timeout for the redis connection configurations.
Try running through this tutorial which might be helpful for troubleshooting the Redis Setup.
Please check a similar example with details node-js-best-practice-exception-handling.

discord.js bot Connection lost: The server closed the connection

so my friend is letting me use his vps for my bot, i made a remote sql so don't say its because i did not connect my sql, that has happend about 3 times already trying to find a fix for this.
So this is the error code that i get in putty
[2019-09-14 14:21:08]: ERROR Uncaught Exception: Error: Connection lost: The server closed the connection.
at Protocol.end (/home/denty/neko-bot/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/home/denty/neko-bot/node_modules/mysql/lib/Connection.js:97:28)
at Socket.<anonymous> (/home/denty/neko-bot/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:214:15)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11)
so about 30-40 min after i node index i get that error
and yea im new to vps so go easy on me
edit: ok so i have did that and it still doesnt work, this is the new error im getting
PROTOCOL_CONNECTION_LOST
db error Error: Connection lost: The server closed the connection.
at Protocol.end (/home/denty/neko-bot/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/home/denty/neko-bot/node_modules/mysql/lib/Connection.js:97:28)
at Socket.<anonymous> (/home/denty/neko-bot/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:214:15)
at endReadableNT (_stream_readable.js:1178:12)
at processTicksAndRejections (internal/process/task_queues.js:77:11) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}
[2019-09-14 15:20:51]: ERROR Uncaught Exception: Error: Cannot enqueue Query after fatal error.
at Protocol._validateEnqueue (/home/denty/neko-bot/node_modules/mysql/lib/protocol/Protocol.js:212:16)
at Protocol._enqueue (/home/denty/neko-bot/node_modules/mysql/lib/protocol/Protocol.js:138:13)
at Connection.query (/home/denty/neko-bot/node_modules/mysql/lib/Connection.js:201:25)
at Client.<anonymous> (/home/denty/neko-bot/index_1.js:186:9)
at Client.emit (events.js:214:15)
at MessageCreateHandler.handle (/home/denty/neko-bot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/home/denty/neko-bot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (/home/denty/neko-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/home/denty/neko-bot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)

Node.js http server crashes with unknown IP address displayed

I am running a Node.js HTTP server, and suddenly the following message is displayed, and the server crashes:
UPDATED ERROR LOG: (after edit)
Uncaught exception in main server
{ Error: connect ETIMEDOUT 139.99.8.126:80
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '139.99.8.126',
port: 80 }
Uncaught exception in main server
{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at Socket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:497:12) code: 'ECONNRESET' }
This is a foreign IP address not used by us.
I tried to grep into all node modules for this IP address and see nothing.
Appears to be a hacking attempt but I have no clue where to start looking.
Any help will be appreciated. I have blocked the IP address in the firewall.
As per node.js docs about errors say:
ETIMEDOUT (Operation timed out): A connect or send request failed because the connected party did not properly respond after a period of time. Usually encountered by http or net — often a sign that a socket.end() was not properly called.
You should create a handler for errors, so your server won't crash:
netSv.on('error', function (error) {
if( error.message.code === 'ETIMEDOUT' ){
// mail the error with some additional data to you or do something with it
}
})

nodejs TLSSocket.onHangUp

I have 2 nodejs modules that communicate via HTTPS.
In very rare occasions, one of the requests to the server module returns:
Stack Trace
Error: socket hang up
at TLSSocket.onHangUp (_tls_wrap.js:1049:19)
at TLSSocket.g (events.js:260:16)
at emitNone (events.js:72:20)
at TLSSocket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickDomainCallback (node.js:397:17)
with errno set to ECONNRESET
Is there any reason why something like that would happen?
I already checked for:
Server crashes before responding
Server response takes too long
certificate expired.
Also, the server logs do not show any kind of problem.
Thanks
ECONNRESET (Connection reset by peer): A connection was forcibly closed by a peer. This normally results from a loss of the connection on the remote socket due to a timeout or reboot. Commonly encountered via the http and net modules.
"Common System Errors" : https://nodejs.org/api/errors.html
so try first to see what's happen
process.on("uncaughtException", function (err) {
console.log('err uncaught Exception : ', err);
})

Node.js redis "unknown command 'hset'"?

I'm new to redis, and I'm trying out various examples. However, it doesn't seem to work:
root#localhost:~# node lol.js
Reply: OK
Error: Error: Error: ERR unknown command 'hset'
Error: Error: Error: ERR unknown command 'hset'
/root/node_modules/redis/index.js:468
throw callback_err;
^
TypeError: Cannot read property 'length' of undefined
at Command.callback (/root/lol.js:15:28)
at RedisClient.return_error (/root/node_modules/redis/index.js:464:25)
at HiredisReplyParser.<anonymous> (/root/node_modules/redis/index.js:253:14)
at HiredisReplyParser.emit (events.js:67:17)
at HiredisReplyParser.execute (/root/node_modules/redis/lib/parser/hiredis.js:41:18)
at RedisClient.on_data (/root/node_modules/redis/index.js:440:27)
at Socket.<anonymous> (/root/node_modules/redis/index.js:70:14)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:367:14)
I'm using one of the example scripts on the github page for node-redis. I'm on Debian Squeeze.
The main problem is not with your code (of course it could recognize the error sent by the server) or with the node redis module but with the Redis server.
You need to upgrade it to a newer version, HSET command is supported since version 2.0.0.

Resources