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

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.

Related

Decentraland project not starting properly

I am trying to run 'dcl start' command from the terminal. The Decentraland Preview webpage opens and terminal says 'Acquring comms connection'. But after that it gives the error below:
Oops, it seems the catalyst isn't working well. [HPM] Error occurred while proxying request 127.0.0.1:8000/lambdas/collections/wearables?collectionId=urn:decentraland:off-chain:base-avatars to https://peer.decentraland.org/ [ECONNRESET] (https://nodejs.org/api/errors.html#errors_common_system_errors) Oops, it seems the catalyst isn't working well. [HPM] Error occurred while proxying request 127.0.0.1:8000/lambdas/collections/wearables?wearableId=urn:decentraland:off-chain:base-avatars:elegant_striped_shirt&wearableId=urn:decentraland:off-chain:base-avatars:elegant_blue_trousers&wearableId=urn:decentraland:off-chain:base-avatars:f_m_sandals&wearableId=urn:decentraland:off-chain:base-avatars:modern_hair&wearableId=urn:decentraland:off-chain:base-avatars:f_mouth_04 to https://peer.decentraland.org/ [ECONNRESET] (https://nodejs.org/api/errors.html#errors_common_system_errors) [HPM] ECONNRESET: Error: socket hang up at connResetException (node:internal/errors:704:14) at TLSSocket.socketOnEnd (node:_http_client:505:23) at TLSSocket.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1358:12) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'ECONNRESET' }
What could cause this error ?

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.

How to use TLSv1.3 with nodejs 10.x

I was trying to make an external api call using https and got the following error.
Error: Client network socket disconnected before secure TLS connection was established
at TLSSocket.onConnectEnd (_tls_wrap.js:1092:19)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
code: 'ECONNRESET',
On further investigation I came to know that my api endpoint uses TLSv1.3 and since I am using nodejs 10.x, I need to set
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
after which it is throwing the following error
TypeError [ERR_TLS_INVALID_PROTOCOL_VERSION]: "TLSv1.3" is not a valid maximum TLS protocol version
at toV (_tls_common.js:49:9)
at new SecureContext (_tls_common.js:74:23)
at Object.createSecureContext (_tls_common.js:100:13)
at Object.connect (_tls_wrap.js:1127:48)
at Agent.createConnection (https.js:120:22)
at Agent.createSocket (_http_agent.js:227:26)
at Agent.addRequest (_http_agent.js:185:10)
at new ClientRequest (_http_client.js:249:16)
at request (https.js:289:10)
at Object.get (https.js:293:15)

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

Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT

I have a sails app. I am running the app in AWS. When i run the code in development mode(sails lift --verbose) it works fine. I am able to access it from the browser bye typing the Ip and port no.(xx.xx.xxx.xx:1337/). But when i run the code in production mode (sails lift --prod --verbose) i am not able to access by ip(xx.xx.xxx.xx) when i try with xx.xx.xxx.xx:1337 it gives me the below error.
Grunt :: Done, without errors.
Unable to parse HTTP body- error occurred:
Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT
at RedisClient.flush_and_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect- redis/node_modules/redis/index.js:142:13)
at RedisClient.on_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:180:10)
at Socket.<anonymous> (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:95:14)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:492:13) [Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT]
Unable to parse HTTP body- error occurred:
Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT
at RedisClient.flush_and_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:142:13)
at RedisClient.on_error (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:180:10)
at Socket.<anonymous> (/home/ubuntu/vka/node_modules/sails/node_modules/connect-redis/node_modules/redis/index.js:95:14)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickDomainCallback (node.js:492:13) [Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT]
please suggest a possible solution.
Check if you are hardcoding the host in session.js with ip, change it to localhost.
For your question on how to access without port 1337, You need to set up a reverse proxy, say NginX, open up just the port 80 for public access, configure nginx to route the request coming to port 80 to your sails app running on port 1337, use something like pm2 or forever to run the sails app.
Steps to setup NginX as reverse proxy is explained here: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

Resources