在Amazon Ec2服务器上丢失数据库连接

时间:2014-10-03 04:51:38

标签: node.js amazon-ec2 amazon sequelize.js node-mysql

在过去的几个月里,我遇到了一个问题,我在amazon ec2服务器上部署了我的应用程序,但每天至少有10到30次我得到这些错误。

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)

知道如何解决这些问题吗?

在发布之前,我在github上发布了类似的问题,我得到了令人不满的答案,这是一个亚马逊问题,很多人都面临着这个问题。

那么就这个问题提出任何建议或解决方案吗?

2 个答案:

答案 0 :(得分:2)

你的错误号码2是我几天前被卡住的地方,我通过clouddueling找到了解决方案 , 这里 https://github.com/aws/aws-sdk-js/issues/55

希望如果您没有面对亚马逊问题,这会有所帮助。

答案 1 :(得分:0)

这实际上可能是DNS问题,具体取决于您的设置。基于您的问题,我假设MySQL数据库安装在与您的应用程序相同的主机上,如果没有,则适用相同的解决方案。

编辑您的主机文件并对您的MySQL主机名和IP地址进行硬编码,然后检查是否解决了您的问题。如果是,那么您需要检查您的名称服务器(使用Google的8.8.8.8和8.8.4.4),并确保您已正确设置DNS。

永远不要对任何东西进行硬编码,只使用此方法来推断DNS是否实际上是原因。