Issue in GCP : getaddrinfo ENOTFOUND issue in Google Cloud Platform - node.js

Getting Error: getaddrinfo ENOTFOUND for external API call.
I have shifted some of my company's infra to GCP. The issue I am facing is that suddenly out of the blue our GCP instances which are behind a VPC are giving us error
Error: getaddrinfo ENOTFOUND somedomain.xyz.in
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:64:26) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'somedomain.xyz.in'
This error suddenly pops up and goes away automatically after sometime.
Sometimes through one instance I am able to ping the above mentioned DNS whereas sometimes the SAME DNS is not ping-able from same instance. I have my billing etc all enabled. If someone has any solution please let me know.
Couple of more details :
I am using Ubuntu18.04 LTS
Instance on GCP are running a NODEJS program which pings the above mentioned external IP using HTTPS.
The external service to which our system pings is hosted on Digital Ocean and is on Public IP and is mapped to a DNS.
The call is made using needle package of NPM.

Related

heroku postgres ETIMEDOUT when conencting through localhost

I have a website which uses the free tier of heroku postgres I was running it on localhost and it was working just fine till today no changes were made to the code and the database url and everything is just fine
Error: connect ETIMEDOUT 3.224.164.189:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1246:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '3.224.164.189',
port: 5432
}
This is the error which I get and this error is only shown on localhost, when the same code is deployed to heroku, it works just fine
Also, one thing which I've noticed is that it works just fine when I use my mobile network and this issue only occurs when I use my ethernet connection.
Can Someone help me out with this sticky situation?

Getting error in node js on running application

I am working on a project where I am using angular in frontend and node on the backend. Everything working fine on the local machine. But on production sometimes I am getting the below error on node side and everything stops working.
I have used https://www.npmjs.com/package/sync-request module in my application
uncaughtException: nodeNC failed:
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:35701
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on Socket instance at:
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) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 35701
}
Error: connect ECONNREFUSED 127.0.0.1:35701 means you may not have started your server and it is not listening to the request
From node.js docs:
ECONNREFUSED (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host.
This is expected. Since you are making HTTP requests using a synchronous package, which states in the docs:
N.B. You should not be using this in a production application. In a node.js application you will find that you are completely unable to scale your server. In a client application you will find that sync-request causes the app to hang/freeze. Synchronous web requests are the number one cause of browser crashes. For production apps, you should use then-request, which is exactly the same except that it is asynchronous.
I would not personally use a package that has been updated for over two years, when during the same period node.js, JS, and browser technologies have updated their APIs rapidly.
The suggestion I can only give you is to use an asynchronous package, in line with the asynchronous architecture of node, that does that in a non-blocking, event-driven way. Choice is yours but bear in mind that you WILL run into these issues from time to time becasue of these design decisions.
If you need additional help, you need to show your server side code so we can redesign the HTTP handler to be asynchronous and eliminate the ECONNREFUSED error at runtime.
Does this help?

Gcloud Postgres wont connect with App Engine

Having a bit of trouble with this. Trying out Google Cloud at the moment and cant my GCloud Postgres db to link to my app engine app.
I'm following everything here :
https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql-postgres
However, when I try to run the createTables.js process I get the following issue:
Failed to create 'visits' table: { Error: connect ECONNREFUSED 127.0.0.1:5432
at Object._errnoException (util.js:1026:11)
at _exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1174:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432 }
Databases aren't really my strong point so I'm a bit stumped.
These are both running in the same GCloud Project also.
Let me know if you need me to supply any more info (not sure exactly what is useful)
Cheers,
Jay
To establish a connection between Google Cloud Postgres and App Engine, try these steps:
Enable the API
Install the proxy client on your local machine
Decide who will authenticate the proxy
Create a service account, in case your authentication method demands it
Decide how you will specify instances for your proxy
Start the proxy
Update your app and connect it to Googe Cloud Postgres

How can I resolve, if EAI_AGAIN error happens on facebook messenger platform?

Our Node.js app for facebook messenger platform threw the following error.
We use "request" module to connect to facebook graph api and the module threw this error. And the problem was resolved without doing anything about 1 hour after I found the problem. So now it's working, but I'm afraid when it'll happen again. Could you teach me this problem and if there is any resolution?
{ Error: getaddrinfo EAI_AGAIN graph.facebook.com:443
at Object.exports._errnoException (util.js:949:11)
at errnoException (dns.js:33:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
code: 'EAI_AGAIN',
errno: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'graph.facebook.com',
host: 'graph.facebook.com',
port: 443 }
Short answer:
This happens when you have lost connection to your DNS server or the DNS settings are wrong (this includes, but is not limited to, complete or partial disconnect from internet).
That is: Please check if your cable or WiFi connection OR your internet provider does not have a (temporary) problem.
Details:
When this happened, I could see in the debugger call stack that the system function getaddrinfo fails. Thus, it seemed like the trivial reason was - the system cannot map the host name to an IP (in your case the host name 'graph.facebook.com" could not be found).
Indeed, when I tried to ping the host name, which I wanted to reach I got the same as ping error like pinging an unknown host:
u#h:~$ ping someunknownhost.xyzdomain
ping: unknown host someunknownhost.xyzdomain
Additionally when, my connectivity to internet recovered and I could ping the host then the problem of node.js also disappeared.

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!

Resources