What is causing Node to randomly fail with - node.js

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?

Related

Why isn't npm start not building and connecting to the dev server?

I'm trying to work my way through a React course and I am consistently running into the same issue. Every time I use npm start after I've created the app I get this error in the browser: This site can’t be reached. Localhost took too long to respond or I get the error that it refused to connect.
Here's everything I've tried to remedy the issue:
I'm not getting any errors in VScode's built in terminal or my laptop's terminal, it says everything compiled successfully.
I've tried opening the dev server on multiple different browsers: Brave, Chrome, Firefox.
I've created multiple different projects & all are having the same issue.
I've changed the port the dev server opens up on in VScode.
I've cleared my node cache.
I've uninstalled & reinstalled node & npm.
I've restarted my laptop multiple times
I've uninstalled & reinstalled VScode.
I even went so far as to completely factory reset my laptop & reinstall everything. It fixed the problem for a couple of days but now I'm back at square one dealing with the same issue.
My laptop is a 2017 MBP 13 running macOS Monterey. Any help / advice would be greatly appreciated.
curl -v "http://localhost:3000"
Trying 127.0.0.1:3000...
* Trying ::1:3000...
* connect to ::1 port 3000 failed: Connection refused
* connect to 127.0.0.1 port 3000 failed: Operation timed out
* Failed to connect to localhost port 3000 after 25918 ms: Operation timed out
* Closing connection 0
curl: (28) Failed to connect to localhost port 3000 after 25918 ms: Operation timed out
```
I finally figured out the solution. I had to turn off my VPN for the npm start command to work.

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

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.

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.

I get a EADDRINUSE error when I try to start a node.js server on OpenShift

So, I successfully commited a node.js app to OpenShift - without getting any error - but it does not work (error 503 when trying to access it through my browser, connection timeout when running tests against it from my local machine). The output when commiting says that node and mysql start successfully, and that the build succeeded.
I accessed the server through ssh, and checked the node log. It says an EADDRINUSE occured: Error: listen EADDRINUSE :::8080.
In my configuration, I use:
"server":{
"host":"OPENSHIFT_NODEJS_IP",
"port":"OPENSHIFT_NODEJS_PORT"
}
I also checked available environement variables in the shell with export and both are there, and 8080 is the right port.
When running ps in the shell, it does show only the programs ps and bash running. EADDRINUSE should mean that the port is already in use by another program, but I don't see anything running... I can't run netstat (permission denied).
I tried various combinations of stop/start/restart, but I always get the same error.
I am pretty lost at this point. Any pointers would be appreciated!
I found the problem. Locally, I used to start the server with app.listen(port);, which is enough to run it and access it on localhost. But that does not work on OpenShift. The host needs to be specified too: app.listen(port, host);.

ECONNRESET proxy error between dev server and API

When I run my development server, I get the following error.
Proxy error: Could not proxy request /graphql from localhost:3000 to http://localhost:3010.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNRESET).
It is preventing me from proxying any requests from the development server to the API.
After debugging, I realized it was not a problem with the code because my colleague and I are working from the same repo and he does not have this error. Also, sometimes if I restart my terminal the error will go away before it comes back again.
Would greatly appreciate guidance on what is the root of this issue and how I can resolve it.
What I discovered, and what seems to have solved the problem, is that I was running too many different servers on ports that were too close together. My servers were running on port 3000, 3010, and 3009. I noticed that whenever the server at 3009 was running, I would get the above error. When I changed the port for that server from 3009 to 9999, all proxy errors ceased.

Resources