Node-redis very long initial connect - node.js

Sometimes my node-redis client take a long time to a initial connect to redis server.
I log .on('error'), .on('end'), .on('connect') and .on('ready') events here:
Redis: storage#0 <localhost:6381> end
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
/*... much of same errors, sometimes up to 5minutes ...*/
Redis: error storage#0 <localhost:6381> [Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]
Redis: storage#0 <localhost:6381> connect
Redis: storage#0 <localhost:6381> ready
While it happened I can normally connect to the redis-server using redis-cli.
Have somebody any ideas about reason of this?

Error "[Error: Redis connection to localhost:6381 failed - getaddrinfo ENOTFOUND]" seems to point to an address resolution issue.
A simple proposal was therefore to use 127.0.0.1 instead of localhost to bypass the call to getaddrinfo, and the associated DNS query which can fail.
The result with 127.0.0.1 was slightly different: still an error, but the message was now ECONNREFUSED meaning that the remote Redis server was probably not listening to the provided port - or perhaps the connection timeout was set too low.

Related

Just installed mongodb cant connect to server on Ubuntu 22.04

I just completed an installation of mongodb in my computer and, after starting and enabling it I keep getting the same error:
MongoDB shell version v4.2.23
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2022-11-10T16:25:32.787+0100 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:353:17
#(connect):2:6
2022-11-10T16:25:32.788+0100 F - [main] exception: connect failed
2022-11-10T16:25:32.788+0100 E - [main] exiting with code 1
I uninstalled and installed multiple times and tried solutions that worked for other people in similar posts but I can not make it work.
I have a feeling it have something to do with the port it is looking for (27017) but I do not know how to check if that is the problem and, if so, how to fix it.
Thanks!
Here are a few things to consider:
Check if the MongoDB process is running (you can verify using ps, netstat (check listen port) command in the server.
See if your MongoDB service runs locally. That is because by default, the listen address of MongoDB is localhost/loopback.
Check if the firewall is running and you have allowed the port.
Verify if you are able to use telnet to command the port 27017 from the application server.

MongoLab - How to resolve ECONNREFUSED

I have a NodeJS application using MongoDB as the database. I'm using mongoose for mongodb related activities.
I have an account in MongoLab and I use that for my database related activities of my application.
When trying to connect to MongoLab as below from nodejs
mongoose.connect("<db_url_with_username_password>", function(err) {
if(err)
{
console.log("Error is "+err);
throw err;
}
});
It's logging the following line
Error is MongoError: connect ECONNREFUSED 54.161.65.217:19058
I thought the server could be down, hence I checked the website online, it's working perfectly.
I pinged the server with the following
ping 54.161.65.217
and it's working fine.
64 bytes from 54.161.65.217: icmp_seq=0 ttl=28 time=271.396 ms
64 bytes from 54.161.65.217: icmp_seq=1 ttl=28 time=268.824 ms
However, When I'm trying to connect using the mongo command to connect, it's failing
mongo 54.161.65.217:19058/<db_name> -u <username> -p <password>
MongoDB shell version: 3.2.1
connecting to: 54.161.65.217:19058/arogyavath
2016-03-14T10:28:27.200+0530 W NETWORK [thread1] Failed to connect to 54.161.65.217:19058, reason: errno:61 Connection refused
2016-03-14T10:28:27.201+0530 E QUERY [thread1] Error: couldn't connect to server 54.161.65.217:19058, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
I looked around and found the following questions which could be similar to mine
Node.js Error: connect ECONNREFUSED
ECONNREFUSED error when connecting to mongodb from node.js
But the answers I found there didn't help me fix the issue.
Could the server ip address be blocked from my network or something? How do I fix this?
I would be very glad if someone can point me in the right direction. Thanks in Advance.

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

redis getaddrinfo ENOTFOUND - node.js , redis connection

Hi im trying to connect to redis from node.js which is successful, now i hosted my node.js server app on amazon ec2 instance and redis on amazon elastic cache instance the connection to redis is succesful but once in a while i'm getting the below mentioned error.
var pub = redis.createClient(6379,'quizredis.qnsdtp.0001.apse1.cache.amazonaws.com');
events.js:72
throw er; // Unhandled 'error' event
^ Error: Redis connection to quizredis.qnsdtp.0001.apse1.cache.amazonaws.com:6379 failed - getaddrinfo ENOTFOUND
at RedisClient.on_error (/home/ec2-user/roomChat-7/node_modules/redis/index.js:196:24)
at Socket.<anonymous> (/home/ec2-user/roomChat-7/node_modules/redis/index.js:106:14)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:813:16
Im using the redis-npm module;
From what I understand, this is a DNS resolution error.
Elasticache Redis is a VPC specific service. Its DNS records are available within the VPC only and often times, VPC is using custom DHCP options with custom DNS server - it may not have the records.
Check a few things -
DNS server configured in your VPC. Check here.
Check the output of nslookup command in your machine - if your using linux shell
nslookup quizredis.qnsdtp.0001.apse1.cache.amazonaws.com
Cheers!

Node Redis EC2 errconnrefuced

There's some strange behavior i've found with node_redis on Aws EC2.
Let's say i have two EC2 instances.
First one is used for DB (Redis, MYSQL, etc.) and it has an IP like so ip-1-1-1-1.eu-west-1.compute.internal
Second one is for app based on NodeJS and it's IP is ip-2-2-2-2.eu-west-1.compute.internal
In the Security Groups i've added this:
6379 sg-351a0441 (default)
6379 sg-333b9044 (quicklaunch-0)
I use node_redis module to communicate with Redis. I need to connect from one instance to another.
So now i (probably) can connect to Redis (first server) from another one:
redis = require('redis');
client = redis.createClient(6379, 'ip-1-1-1-1.eu-west-1.compute.internal');
But this way causes error:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
It tries to connect (!) to 127.0.0.1 istead of 1.1.1.1.
I've said "OK. Let's try another way!"
redis = require('redis');
client = redis.createClient(6379, '1.1.1.1');
And.. BANG! The same error here:
Error: Redis connection to 1.1.1.1:6379 failed - connect ECONNREFUSED
So, maybe full redis url will help?
redis = require('redis');
client = redis.createClient(6379, 'redis://1.1.1.1');
No :(
Error: Redis connection to redis://10.248.118.246:6379 failed - getaddrinfo EADDRINFO
And same one when using internal url:
Error: Redis connection to redis://ip-1.1.1.1.eu-west-1.compute.internal:6379 failed - getaddrinfo EADDRINFO
So, what's wrong with it? Thanks in advance.

Resources