Losing Database Connection on Amazon Ec2 Server

For the last few months I am facing an issue, I deployed my application on amazon ec2 server but at least 10 to 30 times a day I get these errors.

1) Error: connect ETIMEDOUT
    at errnoException (net.js:904:11)
    at Object.afterConnect [as oncomplete] (net.js:895:19)

2) Error: getaddrinfo ENOTFOUND
     at errnoException (dns.js:37:11)
     at Object.onanswer [as oncomplete] (dns.js:124:16)
     --------------------
    at Handshake.Sequence                                            (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Handshake (/var/app/current/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:42:50)
at Connection.connect (/var/app/current/node_modules/mysql/lib/Connection.js:72:18)
at module.exports.connect (/var/app/current/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:276:16)
at Object.pool.Pooling.Pool.create (/var/app/current/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:125:19)
at createResource (/var/app/current/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:258:13)
at dispense (/var/app/current/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:250:9)
at Object.me.acquire (/var/app/current/node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:316:5)
at module.exports.enqueue (/var/app/current/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:320:19)

3) TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at EventEmitter.emit (events.js:74:15)
at Handshake._callback (/var/app/current/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:286:19)
at Handshake.Sequence.end (/var/app/current/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
at Protocol.handleNetworkError (/var/app/current/node_modules/mysql/lib/protocol/Protocol.js:238:14)
at Connection._handleNetworkError (/var/app/current/node_modules/mysql/lib/Connection.js:155:18)
at Socket.EventEmitter.emit (events.js:117:20)
at net.js:830:16
at process._tickDomainCallback (node.js:459:13)

Any idea how to fix these issues ?

Before posting here I posted similar question on github as well and I got unsatisfactory answer that this is an amazon issue and many of the people are facing it.

So guys any suggestion or solution regarding this issue ?

Your error number 2 is where I was stuck few days ago, I found a solution by clouddueling , here https://github.com/aws/aws-sdk-js/issues/55

hope this helps, if you are not facing an amazon issue.

This could in fact be a DNS issue depending on your set-up. Based on your question I am presuming that the MySQL database is installed on that same host as your application, if not, the same solution would apply.

Edit your hosts file and hardcode your MySQL hostname and IP address and check to see if that resolved your problem. If it does then you need to check your nameservers (use Google's 8.8.8.8 and 8.8.4.4), and make sure that you've set-up your DNS correctly.

Never hardcode anything, only use this method to deduce if DNS is in fact the cause.