Error: Redis connection to 10.130.212.246:6379 failed - connect ETIMEDOUT - node.js

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

Related

Unable to use MongoDB on GCP cloud run and connect it to a NodeJS

I am testing a nodejs app on GCP functions and a MongoDB instance in GCP cloud run(I know this is not a good idea) but again this is a test. I am able to get the mongo image running on cloud run and I am given a service endpoint as https://mongodb.foo.bar.run.app and I have the container port in this cloud run service as 27017.
When I try and edit the mongoose.connect() method to include this service uri I am not able to connect with the app. I have the mongodb cloud run instance open to receive traffic from all traffic(Again not a good idea), but I still can't get the node app to connect.
I have setup the connection in node as mongoose.connect('mongodb://mongodb.foo.bar.run.app:27017/test');
but I get this error
Error: connect ETIMEDOUT <IP ADDRESS GOES HERE>:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
at TCPConnectWrap.callbackTrampoline (internal/async_hooks.js:129:14)
Emitted 'error' event on NativeConnection instance at:
at NativeConnection.Connection.error (/Users/foo/nodejs/bar/node_modules/mongoose/lib/connection.js:443:8)
at /Users/foo/nodejs/bar/node_modules/mongoose/lib/connection.js:472:15
at /Users/foo/nodejs/bar/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:21
at /Users/foo/nodejs/bar/node_modules/mongodb/lib/db.js:232:14
at Server.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb/lib/server.js:240:9)
at Object.onceWrapper (events.js:421:26)
at Server.emit (events.js:314:20)
at Pool.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/topologies/server.js:308:68)
at Pool.emit (events.js:314:20)
at Connection.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/connection/pool.js:115:12)
at Object.onceWrapper (events.js:421:26)
at Connection.emit (events.js:314:20)
at Socket.<anonymous> (/Users/foo/nodejs/bar/node_modules/mongodb-core/lib/connection/connection.js:144:49)
at Object.onceWrapper (events.js:421:26)
at Socket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:100:8) {
name: 'MongoError'
}
I tried to curl the service uri as
curl https://mongodb.foo.bar.run.app
and I get a 200 response in the mongo logs GET 200 466B but if I
curl mongodb.foo.bar.run.app
I get a 302 response code GET 302 0B.
I looked at the mongoose documentation but I couldn't figure what I was doing wrong. I know the documentation states user and password on the uri string, but when I run it locally on my docker engine I did not use a user and password and it worked.
As mentioned in the comments, it's not possible to run MongoDB on Cloud Run since as mentioned here:
Cloud Run can only receive HTTP requests or Pub/Sub push events.
Connecting to MongoDB requires a TCP protocol rather than HTTP, that's why every call to it would fail even if the port is reachable.
Cloud Run is in this sense more similar to AWS Lambda than it's to AWS Fargate as it's even billed on a per request basis rather than on resources consumed.

MongoError : Server 127.0.0.1:3000 timed out at null

I am getting an error in cmd when i run "node app.js" command.
"facebook-auth\express-authentication" is my path to NodeJS project.
I run my MongoDB and i think it is working fine.
and
When i use "node app.js" command in starting then my "http://127.0.0.1:3000" server work fine but when i close all connections and try to restart mongoDB then is error occur everytime.
I don't know how to solve this problem and this project is running fine in starting on http://127.0.0.1:3000. But don't know what happened know. I closed my MongoDB using Ctrl+C.
After adding this code
// When successfully connected
mongoose.connection.on('connected', function () { console.log('Mongoose default connection open to ' + dbURI); });
// If the connection throws an error
mongoose.connection.on('error',function (err) { console.log('Mongoose default connection error: ' + err); });
to app.js it shows this:
Showing an error and website authentication not work properly(But website is running now). It don't get callback information from localhost or 127.0.0.1. It keeps waiting for response for localhost and callback doesn't complete (stuck there).
I follow this tutorial :Here and project is working fine.
"Is this a conflict between xampp or mongoDB or nodeJS"
App.js file linked Here
Thanks in advance for help.
Waiting for connections on port 27017.
Vs.
Server 127.0.0.1:3000 timed out.
Don't let me think everything is fine.
You either have to change the port, where app.js is connecting to, to Mongo's standard port 27017, or start mongod with --port 3000 to listen on port 3000.
I was facing the same problem and this is what I got each time I run my app.
/home/sarojs/projects/ror/liveProject/bq-ng/brandqast- ng/node_modules/mongoose/node_modules/mongodb/lib/server.js:242
process.nextTick(function() { throw err; })
^
MongoError: server 127.0.0.1:8080 timed out
at null.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:436:40)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at null.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:144:10)
at g (events.js:260:16)
at emitTwo (events.js:87:13)
at emit (events.js:172:7)
at Socket.<anonymous> (/home/sarojs/projects/ror/liveProject/bq-ng/brandqast-ng/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:172:12)
at Socket.g (events.js:260:16)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at TCP._onclose (net.js:469:12)
I found that the mongoDB URI that I was setting was 8080 as port no.
I simply changed the port to 27017 as it is the default port. It worked perfectly fine.

Not able to connect to mongodb when start node server

I am trying to run my node app locally on my VM.
When I am running command:
sudo NODE_ENV= XYZ PORT=80 node server/app.js
I'm getting error:
/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/mongo_client.js:378
throw err
^ Error: connection closed
at null. (/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/server.js:605:24)
at emit (events.js:92:17)
at null. (/node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:155:15)
at emit (events.js:98:17)
at Socket. (//node_modules/mongo-oplog/node_modules/mongodb/lib/mongodb/connection/connection.js:528:12)
at Socket.emit (events.js:95:17)
My mongoDB is running fine and I can connect to local db with robomongo.
Any help would be highly appreciated on this.

Openshift redis cartridge with strange exceptions ETIMEDOUT on socket.io script

I have a socket.io node script running that acts as a chat server. I had it running on a local server ok, and have since tried moving it over to openshift.
I used the following cartridge to get it working - https://github.com/smarterclayton/openshift-redis-cart/issues
While running the local version of the server, while connecting to the openshift redis, I get strange timeouts exactly 127 seconds after I run the script.
events.js:72
throw er; // Unhandled 'error' event
^
Error: Redis connection to <server> failed - connect ETIMEDOUT
at RedisClient.on_error (/path/node_modules/redis/index.js:196:24)
at Socket.<anonymous> (/path/node_modules/redis/index.js:106:14)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
I have seen the events.js:72 one before, but its usually when I try to run a node script with something already running on that port.
Pretty sure the script itself is fine, as when I swap out the redis server for my local one, it will sit there for days and work fine.
So my question: why is my socket.io script killing itself after exactly 127 seconds when redis is hosted on openshift?
Are you using the rhc port-forward command so that you can connect to redis on OpenShift? Otherwise that port is not publicly available.

Mongoose Can't Connect Without Internet

I have my MongoDB server running on localhost:27017, and while I can usually run my Node.js app fine, when I disconnect from the internet Mongoose throws the error
Error: failed to connect to [localhost:27017]
Note that I can still connect to the MongoDB server from the Mongo shell client. Also, if I start up my app first and then lose internet connection, my app can access the database fine offline. So why can't it start up without internet?
EDIT: here is the error in full
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\server.js:555:74)
at emit (events.js:118:17)
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\connection_pool.js:156:15)
at emit (events.js:110:17)
at Socket.<anonymous> (<My App>\node_modules\mongoos
e\node_modules\mongodb\lib\mongodb\connection\connection.js:534:10)
at Socket.emit (events.js:107:17)
at net.js:923:16
at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...
Edit: wording
Use 127.0.0.1 instead of localhost. By turning off your wifi interface the OS is no longer able to resolve localhost.
Consider node-offline-localhost.
Add the following before the breaking code:
require('node-offline-localhost').always();
And it just works (hopefully), at least until RFC 3493 gets fixed.
Full disclosure: I authored this package to streamline https in my dev environment when offline.

Resources