Node.js HTTP requests: "EAI_AGAIN" DNS errors on Raspberry Pi - node.js

I have a node.js server that fetches data from several APIs.
Most of them are constantly giving this same error over time when fetching an http request with axios:
errno: -3001,
code: 'EAI_AGAIN',
syscall: 'getaddrinfo'
This is only happening on my Raspberry Pi. If I run this server on say my PC this error doesn't occur.
I'm guessing this is a DNS timeout? Why does this happen only on my raspberry pi? (it's connected to the same network as my PC).
Do I need to extend the timeout (and if so, how?) or is there a linux command I need to issue or a node package I need to install?
This is happening quite frequently.

Related

Error on npm start on Azure - EADDRNOTAVAIL

I'm trying to get a nodejs app running on Azure (which runs perfectly fine on Heroku).
After running npm start on the app, the following error happens:
Error: connect EADDRNOTAVAIL 127.0.0.1 - Local (0.0.0.0:56256)
at internalConnect (net.js:907:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:301:12)
at net.js:998:9
at processTicksAndRejections (internal/process/task_queues.js:75:11) {
errno: 'EADDRNOTAVAIL',
code: 'EADDRNOTAVAIL',
syscall: 'connect',
address: '127.0.0.1'
}
I've tried setting various ports which are free, but no matter what, I get this error.
UPDATE
I know that your current program runs normally in Heroku, and it runs very well locally.
But what I want to tell you is that in azure webapp, there is no need to execute the npm start command to start the webapp. After you pass the deployment, you can set the Startup Command in the portal to start your application. For general nodejs projects, the startup command is npx serve -s.
So you said that the execution of npm start produces an error. If you execute this start command in kudu, it is inappropriate.
If an error occurs when running locally, such as connect EADDRNOTAVAIL 127.0.0.1-Local (0.0.0.0:56256), it is recommended that you use netstat -ano|findstr "56256" to check which process uses the port and deal with.
PRIVIOUS
You need to macke sure use process.env.PORT || 3000 in your project. And you need to know, the port in azure webapp just support 80 and 443. So in your project, So in your code, there can only be one PORT value. After deployed, 443 and 80 will work.
And you can run your app perfectly on HeroKu. So I suggest you upload your code to github.
Then you can deploy your webapp by git. And your issue will be solved. If also have error when deploy, you can check the error in Action on git.

Error: getaddrinfo ENOTFOUND

I have a simple Node.js bot that makes an HTTP request each second to a rest API.
If the returned data is right then I construct an URL where I HTTP POST.
Everything works alright but after ~4-5hrs of running I got this error
0|server | error: Error: getaddrinfo ENOTFOUND www.rest-api.com www.rest-api.com:443
0|server | at errnoException (dns.js:28:10)
0|server | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)
Can someone explain to me why this has happened?
After I restart my server everything got working.
I'm using axios to make the http requests.
I met the same issue and solved it!
try:
sudo vi /etc/hosts
and add:
127.0.0.1 localhost
to hosts
The symptom is that the remote address cannot be resolved.
The cause could be many things. First, try to see if it's node specific by trying to resolve the address directly:
$ nslookup www.rest-api.com
Or:
$ dig www.rest-api.com
If that doesn't work, you've got a connectivity problem. It could be anything. Try looking at how long your DHCP lease lasts if you are using DHCP.
However if that does work fine but your node application still fails, you might be running into this: https://github.com/nodejs/node/issues/5436 , which is a bug in an underlying library. You can implement the workaround mentioned in that thread, which is specifying the IP version family through the following parameter { family: 4 } as a part of your request options.
I had this issue becuase there was a typo in my URL - the path did not exist. Gotta be careful with long subdomain URLs. I discovered the issue while using the Postman Console - available by going to View > Show Postman Console.
I got this error in Postman when I didn't have the Environment I wanted to use selected. The variables I was trying to call were therefore not defined.

Unhandled rejection SequelizeConnectionError: connect ENOENT

I am stuck at a point. I am trying to start /connect using command "npm start" but unable to start npm on server.
I am getting this error:
Unhandled rejection SequelizeConnectionError: connect ENOENT
at Handshake._callback (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:63:20)
at Handshake.Sequence.end (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Protocol.handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/Protocol.js:358:14)
at Connection._handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/Connection.js:382:18)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
Apart from this my website work on nodejs & have nginx server configured on server.
Every thing started when I tried to set apache for adding a wordpress blog website. Since nginx already working on port 80. I was trying to set apache on another port so that everything work and ended up with above error. Now my website is not starting at all.
Edit:
My website is running using nodejs. I needed a wordpress blog website to run along and so i checked if there is a scope for apache on my server.
I found that apache along with nginx service was already running and mysql as well.
nginx is essential to run "adminer", a database management tool
Since nginx and apache was running on same ports, i tried to set apache on another port, other than default port.
After that I restarted apache, stopped mysql, stopped nginx and also stopped node
I used pkill node command for stopping node service.
Then restarted everything but got the above error.
I tried many things, and finally reset everything.
Ever since then I am stuck on this error.
Can anyone help?
I finally figured the problem and solved it.
Connect ENOENT means that system is unable to connect to mysql because its path is not correct.
As mentioned in an approved answer from Connect MySQL with Sequelize
Update your models/index.js file with the mentioned code.
To find you mysql socket path go to file here /etc/mysql/my.cnf ( this path may depend on your server). For my case it was /etc/my.cnf. Here you will find the socket path. Now paste this path to the code above and do npm start.
Problem is resolved. :)

What is causing Node to randomly fail with

I have a node application that I run behind a proxy and make requests using the request lib. Everything works fine under most circumstances but every now and then (once every few minutes) I see the following error
{ [Error: tunneling socket could not be established, cause=Parse Error] code: 'ECONNRESET' }
There was an error {"code":"ECONNRESET"}
Finally after a minute or so it starts working again. Any ideas as to what could be causing this?

Error: connect ECONNREFUSED when making https request on same server running nginx

Since a recent Plesk update on my server I been having issues with my nodejs apps making requests to api urls hosted on the same server and a bit lost as to whats causing it as they use to run fine. The api domain in question is still serving the site using apache but when my nodejs app makes a request to the site using https I get the error
{ [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }
however loading the same url in my browser loads fine.

Resources