我的Firebase云功能提供SequelizeConnectionError:每当我查询MySql DB时都会连接ETIMEDOUT错误

时间:2018-06-23 12:10:39

标签: mysql node.js firebase sequelize.js google-cloud-functions

问题描述:

我正在使用Sequalize ORM和Firebase云函数,当我查询MySql数据库时,给出 SequelizeConnectionError:connect ETIMEDOUT 错误。当功能通过Firebase cli在localhost上运行时,它可以正常工作。 下面是Sequalize连接方法。

代码段

var sequelize = new Sequelize('dbname, 'username', 'password', {
host: "host",
dialect: 'mysql',
define: {
    paranoid: true
},
pool: {
    max: 5,
    min: 0,
    acquire: 30000,
    idle: 1
},
operatorsAliases: false})

当功能通过Firebase CLI在端口5000上本地运行时,上面的代码运行完美。当我在Firebase上部署它并运行相同的功能时,我得到的错误更少。

2018-06-23T11:31:53.887Z E app: Unhandled rejection
2018-06-23T11:31:55.187Z E app: SequelizeConnectionError: connect ETIMEDOUT
    at Utils.Promise.tap.then.catch.err (/user_code/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:149:19)
    at tryCatcher (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:689:18)
    at Async._drainQueue (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14
)

2 个答案:

答案 0 :(得分:1)

这很可能是因为您的Firebase项目采用了免费的Spark付款计划。使用Spark,您的Cloud Functions无法建立与不受Google完全控制的服务的传出连接。要建立传出连接,您必须将项目升级到其中一种付款计划,例如Blaze。

Read more on the Firebase pricing page.

答案 1 :(得分:0)

您可能只允许使用最大大小为1的池。