nodejs TLSSocket.onHangUp - node.js

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);
})

Related

Getting read ECONNRESET at TCP.onStreamRead error, while making connection with AZURE server

Hi all I am learning Nodejs. I am uploading file to AZURE server, but getting the below error after every 3-4 minutes. Anyone have the solution for this?
The error is ->
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
Emitted 'error' event at:
at Connection._handleProtocolError
(/Data/core/node_modules/mysql/lib/Connection.js:425:8)
at Protocol.emit (events.js:198:13)
at Protocol.EventEmitter.emit (domain.js:448:20)
at Protocol._delegateError
(/Data/core/node_modules/mysql/lib/protocol/Protocol.js:390:10)
at Protocol.handleNetworkError
(/Data/core/node_modules/mysql/lib/protocol/Protocol.js:363:10)
at Connection._handleNetworkError
(/Data/core/node_modules/mysql/lib/Connection.js:420:18)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:448:20)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one or more application protocol errors. You could look at the API server logs to see if it complains about something.
Glad #RakeshSaini that you identified the error which was in the connection waiting limit in the MySQL and for fixing the issue.

Vercel Serverless function with nuxtjs ECONNRESET Client network socket disconnected before secure TLS connection was established

so i'm having this problem on a nuxt implementation with vercel, at random moments the site doesn't load and throws a 502 http error
this is the stacktrace of vercel:
ERROR Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","reason":{"errorType":"FetchError","errorMessage":"request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","code":"ECONNRESET","message":"request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established","type":"system","errno":"ECONNRESET","stack":["FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established"," at ClientRequest.<anonymous> (server.js:16011:11)"," at ClientRequest.emit (events.js:315:20)"," at ClientRequest.EventEmitter.emit (domain.js:483:12)"," at TLSSocket.socketErrorListener (_http_client.js:426:9)"," at TLSSocket.emit (events.js:315:20)"," at TLSSocket.EventEmitter.emit (domain.js:483:12)"," at emitErrorNT (internal/streams/destroy.js:92:8)"," at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)"," at processTicksAndRejections (internal/process/task_queues.js:84:21)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: FetchError: request to {api_url} failed, reason: Client network socket disconnected before secure TLS connection was established"," at process.<anonymous> (/var/runtime/index.js:35:15)"," at process.emit (events.js:327:22)"," at process.EventEmitter.emit (domain.js:483:12)"," at processEmit [as emit] (/var/task/node_modules/signal-exit/index.js:161:32)"," at processPromiseRejections (internal/process/promises.js:209:33)"," at processTicksAndRejections (internal/process/task_queues.js:98:32)"]}
Unknown application error occurred
So the error it's about a connection with the api, for what i found this is a Node error but my api is developed on Laravel so i'm really lost
Thanks for the help
I ran into this issue (with a Next.js project on Vercel) and fixed it. I was calling an external API but forgot to await one of the handlers, so the Lambda eventually stopped waiting for the API call response once my code finished running.

Node.js Error: Unexpected server response: 301 - Running a Node.js Websocket server on Namecheap Webhost

I'm trying to setup a Node.js Websocket server over at my webhost (Namecheap). However, I am getting this error:
events.js:292
throw er; // Unhandled 'error' event
^
Error: Unexpected server response: 301
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
at ClientRequest.emit (events.js:315:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:596:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at TLSSocket.socketOnData (_http_client.js:469:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at TLSSocket.Readable.push (_stream_readable.js:212:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on WebSocket instance at:
at abortHandshake (D:\****\node_modules\ws\lib\websocket.js:694:15)
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
[... lines matching original stack trace ...]
at TLSSocket.Readable.push (_stream_readable.js:212:10)
The code for the client and server came from here:
https://github.com/websockets/ws#Simple server
https://github.com/websockets/ws#sending-and-receiving-text-data
with ws://www.host.com/path changed to ws://<mydomainname>/<dir1>/<dir2>
Both client and server code runs properly when run locally. Http related code runs properly when used on my webhost. I am trying to get the client code to run locally and connect via websockets to my server hosted at Namecheap.
I suspect something related to the server is preventing connection. I'd ask support but I doubt if they can resolve this. Maybe there's a locked feature or something? Is there something else I could have missed?
Websockets cannot work on Namecheap's hosted servers. Their incoming ports are blocked and cannot be opened for security reasons per their customer's support.
If anyone is looking for a solution just in case, try out a Heroku free account.

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
}
})

Cannot connect to Mongo Server

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.

Resources