I have 3 servers which run a MongoDB replicaset, 1 primary, 1 secondary, 1 arbiter. And I have problem connecting to this replicaset. Tested with a test.js file which runs on localhost and a spare server.
Connect from localhost, node 6.5.0: OK
Connect from localhost, node 10.15.1: FAILED
Connect from the spare server, node 6.5.0: OK
Connect from the spare server, node 10.15.1: OK
Here's my test.js file:
const MongoClient = require("mongodb").MongoClient;
const url = "mongodb://root:password"+
"#mgdb1.mydomain,mgdb2.mydomain/vApp?replicaSet=rs0&authSource=admin";
console.log("Connecting...");
MongoClient.connect(url,(err,client)=>{
if (err!=null){
console.log("Error:",err);
return;
}
console.log("Connected.");
process.exit();
});
The strange thing is that it shows ECONNREFUSED error, but not at the IP of the 3 servers in the replicaset, it's the IP in range of my ISP. So why does it fail afterConnect? It shows TCPConnectWrap.afterConnect, does it mean the connection is already made?
The error is this way:
Connecting...
(node:1412) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Error: { Error: connect ECONNREFUSED 125.235.4.59:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '125.235.4.59',
port: 27017 }
Edit:
My current work-around is connecting directly to the primary server without replicaset=rs0, however, this is not the desired manner.
I found out the problem. When created the replica set on a group of machines on cloud, the addresses to the servers are server names which are known only by other machines on the same server LAN. On localhost in office, there are no such server names.
Work-around 1:
Connect only to the primary or secondary server
Work-around 2:
Edit /etc/hosts file (or c:\windows\system32\drivers\etc\hosts)
Point the name of the servers to their appropriate IPs
Related
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?
while trying to connect to my cloudsql instance I am getting this error
{
errorno: "ETIMEDOUT",
code: "ETIMEDOUT",
syscall: "connect",
fatal: true
}
this is the log from my cloudsqlproxy container
2020/06/09 15:53:04 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2020/06/09 15:53:04 using credential file for authentication; email=lion-db#estatelion-test-275318.iam.gserviceaccount.com
2020/06/09 15:53:04 Listening on 127.0.0.1:3306 for estatelion-test-275318:us-central1:estatelion
2020/06/09 15:53:04 Ready for new connections
but my nodejs application is unable to connect to it
const connection = mysql.createPool({
connectionLimit: 10,
host: config.get("database").host, // localhost
user: config.get("database").user, // cloud proxy user for my cloudsql instance
password: config.get("database").password, // password
database: config.get("database").db_name, // database
});
Well I found the solution to this
I just updated the Cluster version to 1.15.11-gke.15 from 1.14.* (I dont remember the rest ) and it worked fine.
I think there is some bug in the default GKE version of the deployment.
Thanks Everyone for your gracious time and effort. :-)
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
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.
After deploying the Ghost blogging platform with success, i tried to configure it to use Mysql instead of sqllite3 using this database section of their config page, which says:
Database
By default, Ghost comes configured to use an SQLite database, which
requires no configuration.
Alternatively Ghost can also be used with a MySQL database by changing
the database configuration. You must create a database and user first,
you can then change the existing sqlite config to something like:
database: { client: 'mysql', connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'ghost_db',
charset : 'utf8' }
}
So ok, the setup is straight forward. but i'm still unable to connect ghost with mysql. The error i receive after starting the platform using npm start --production is :
> ghost#0.6.2 start /var/www/ghost
> node index
Migrations: Database initialisation required for version 003
Migrations: Creating tables...
Migrations: Creating table: posts
ERROR: connect ECONNREFUSED
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
--------------------
at Protocol._enqueue (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:110:48)
at Protocol.handshake (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:42:41)
at Connection.connect (/var/www/ghost/node_modules/mysql/lib/Connection.js:98:18)
at /var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:105:16
at tryCatch2 (/var/www/ghost/node_modules/bluebird/js/main/util.js:53:21)
at Promise._resolveFromResolver (/var/www/ghost/node_modules/bluebird/js/main/promise.js:544:13)
at new Promise (/var/www/ghost/node_modules/bluebird/js/main/promise.js:84:37)
at Client_MySQL.acquireRawConnection (/var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:104:10)
at Object.create (/var/www/ghost/node_modules/knex/lib/pool.js:33:19)
at Object.Pool.createResource (/var/www/ghost/node_modules/knex/node_modules/generic-pool-redux/pool.js:288:12)
I'm not sure what could be wrong, since i have other applications using mysql working without any problems.
Thanks in advance.
connection refused = tcp connection was attempted, but nothing is listening on the port, or was explicitly denied. Unless you explicitly enabled TCP support in mysql (and have the correct ip/port), you should probably be using a local unix-domain socket instead.