Firebase函数产生SequelizeConnectionError:连接ETIMEDOUT

时间:2019-03-07 21:43:20

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

当前,我正在使用Firebase Function作为我正在使用的应用程序的node.js后端。我也使用Sequalize ORM与MySQL数据库连接。在两个或两个以上的星期中,它完全可以正常工作,但是现在每次我甚至尝试启动应用程序时,都会出现此错误:SequelizeConnectionError:连接ETIMEDOUT。

Unable to connect to the database: { 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:690:18)
at _drainQueueStep (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues (/user_code/node_modules/sequelize/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)

具有Sequelize连接的Index.js的定义如下:

// Dependecies
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');

// App init
const app = express();

// Database Init
const db = require('./configs/db')
db.authenticate()
.then(() => console.log('Connection has been established successfully.'))
.catch(err => console.error('Unable to connect to the database:', err));

// CORS Middleware
app.use(cors());

// Routes
const lists = require('./routes/lists.js');
const tombs = require('./routes/tombs.js');
const doors = require('./routes/doors.js');
const fullTextSearches = require('./routes/ftSearch.js');
const lytics = require('./routes/lytics.js');

// BodyParser Middlware
app.use(bodyParser.json({
  limit: '50mb'
}));

// Routes use
app.get('/api/test', (req, res) => res.send('Api is working!'));

app.use('/api/tombs/', tombs);
app.use('/api/doors/', doors);
app.use('/api/ftsearch/', fullTextSearches);
app.use('/api/lytics/', lytics);
app.use('/api/lists/', lists);

// ------------------------
// Function export
// ------------------------
exports.main = functions.https.onRequest(app);

和configs / db.js

const db = new Sequelize('db', 'user', 'passwd', {
  host: 'host',
  dialect: 'mysql',
  pool: {
      max: 1,
      min: 0,
      acquire: 30000,
      idle: 10000
  },
  operatorsAliases: false,
  logging: false
});

module.exports = db;

我正在使用的MySQL服务器是一种共享托管服务。应用程序前端托管在Firebase托管中。当我使用Firebase CLI运行相同的应用程序时,连接非常好。问题只有在我部署它时才会发生。帐单帐户似乎有问题,但我有Blaze计划,尚未超出任何限制。与this question中的问题基本上相同,但是没有答案,至少有一个可以解决我的问题。

更改池大小根本没有帮助。我能够找到的任何其他答案都表明这是Spark计划的问题,但是我使用的是Blaze,所以我现在有点迷路了...

0 个答案:

没有答案