Closed nizarp closed 8 years ago
Hi @nizarp, there isn't much we can really help with here, as the error you have provided indicates that the TCP connection could not be established within 10 seconds to the RDS host. Typically this means you have some kind of firewall rule dropping traffic somewhere between your code and the RDS host. I hope that helps!
@dougwilson , will you help me to solve this problem...
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (/var/www/html/server1/node_modules/mysql/lib/Connection.js:425:13)
at Socket.g (events.js:286:16)
at emitNone (events.js:86:13)
at Socket.emit (events.js:185:7)
at Socket._onTimeout (net.js:333:8)
at tryOnTimeout (timers.js:228:11)
at Timer.listOnTimeout (timers.js:202:5)
--------------------
at Protocol._enqueue (/var/www/html/server1/node_modules/mysql/lib/protocol/Protocol.js:141:48)
at Protocol.handshake (/var/www/html/server1/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/var/www/html/server1/node_modules/mysql/lib/Connection.js:136:18)
at Object.<anonymous> (/var/www/html/server1/app1.js:35:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
This is my code :-
var bodyParser = require('body-parser');
var express = require('express');
var config = require('./config/config');
var io = require('socket.io')();
var openDB = require('json-file-db');
var db = openDB('db.json');
var mysql = require('mysql');
var gcm = require('node-gcm-service');
var apn = require('apn');
var app = express();
app.listen(config.HTTP_PORT); // 3000
app.use(bodyParser.json());
io.listen(config.SOCKET_PORT);//7777
console.log("Server is up");
var connection = mysql.createConnection({
host : 'xx.xx.xxx.xxx',
user : 'root',
password : 'my_password',
database : 'my_db'
});
connection.connect(function(error){
if(!!error)
{
console.log(error);
console.log('Error');
}
else
{
console.log('connected');
}
});
@sandhibaljeet In my case, it was a Lambda function and I had to increase the Timeout setting for the Lambda function to fix this. Are you also trying this from a Lambda function. If so, try increasing the the Timeout.
I am new o this, please tell me how to do settings
I just updated my last comment. Please check.
Will you please give me some code snippet that how to do settings. Because i don't know in which file or where to increase the time. I am totally new to this
Did you try adding a timeout?
var connection = mysql.createConnection({
host : 'xx.xx.xxx.xxx',
user : 'root',
password : 'my_password',
database : 'my_db',
timeout: 60000
});
still that error
@sandhibaljeet Were you able to connect to the database directly, (to make sure the DB works fine)? Are you available on google chat?
@nizarp there is another error m facing right now, please help me, these are server logs .In mysql query i fetch all usernames and print them, but after fetching the first username there is error. connected Test server ping succes successfully executed john /var/www/html/server1/node_modules/mysql/lib/protocol/Parser.js:78 throw err; // Rethrow non-MySQL errors ^
RangeError: Invalid status code: 0 at ServerResponse.writeHead (_http_server.js:192:11) at ServerResponse._implicitHeader (_http_server.js:157:8) at ServerResponse.OutgoingMessage.end (_http_outgoing.js:558:10) at ServerResponse.send (/var/www/html/server1/node_modules/express/lib/response.js:205:10) at Query._callback (/var/www/html/server1/app1.js:80:30) at Query.Sequence.end (/var/www/html/server1/node_modules/mysql/lib/protocol/sequences/Sequence.js:85:24) at Query._handleFinalResultPacket (/var/www/html/server1/node_modules/mysql/lib/protocol/sequences/Query.js:144:8) at Query.EofPacket (/var/www/html/server1/node_modules/mysql/lib/protocol/sequences/Query.js:128:8) at Protocol._parsePacket (/var/www/html/server1/node_modules/mysql/lib/protocol/Protocol.js:280:23) at Parser.write (/var/www/html/server1/node_modules/mysql/lib/protocol/Parser.js:74:12) ~
This is entirely a different issue. Let's not discuss this here.
I am experiencing a similar issue. when connecting from a local express server, all works. but from lambda, I got the TIMEOUT error but only on INSERT operations.. the SELECT operations works fine!
Did you try increasing the the Timeout for Lambda function?
For AWS Lambda: 10 seconds didn't work for me, but increasing timeout to 15 seconds is working so far
Hey guys, the way I solved this issue was to update the security group in aws since RDS generates a default group with the local machine ip address. If you are trying to connect to the database from another app that is in another instance, you should add the ip address in the security group. Hope it helps!
@leojle Thank you! I'm new to lambda functions and I spent an entire day debugging trying to figure out why I couldn't connect. For others running into this problem and making it all the way down here without a fix:
On your Lambda function, specify your VPC, subnets, and Security Groups. Then, like @leojle mentioned, you need to add the Security Group that you selected on your Lambda function to the Security Group you have defined for your RDS( In my case they were both the same Security Group ). You have to add the Group Id to the Inbound rules( you can add an IP address or a Group Id to the rules set ).
hii am getting the same error and i tried to add timeout?
var connection = mysql.createConnection({ host : 'xx.xx.xxx.xxx', user : 'root', password : 'my_password', database : 'my_db', timeout: 60000 }); please someone help me out
@ruchigaba your problem is likely a security groups problem, as the comment right above yours suggests. hope you can figure it out, this stuff's tricky :|
I'm trying to connect to RDS from EC2 and still get this ETIMEOUT issue
Solved by updating RDS security group inbound rule to accept from "0.0.0.0/0". If you need more secure config, attach Lambda to new SG and add that new lambda-SG in RDS-SG inbound rules.
I had the same issue and @agarhy was right. Set the security group inbound rule to accept from "0.0.0.0/0".
Hey
This is not an issue. But I need help to find out what I am doing wrong. I am trying to connect to my Amazon RDS instance. But I am getting "connect ETIMEDOUT" error.
At the same time I am able to connect from my local MySQL Workbench with the same details.
Here is my code:
Output is: