我在我的风帆应用程序中有这个控制器代码:
let userId = req.body.userId;
User.findOne({ id: userId })
.then((user) => {
console.log('User found:', user);
return res.ok('It worked!');
}).catch((err) => {
sails.log.error('indexes - error', err);
return res.badRequest(err);
});
当我启动我的服务器时,它可以工作,但是经过一段时间(约5分钟)它停止工作,我最终得到以下错误信息:
web_1 | Sending 400 ("Bad Request") response:
web_1 | Error (E_UNKNOWN) :: Encountered an unexpected error
web_1 | MongoError: server 13.81.244.244:27017 received an error {"name":"MongoError","message":"read ETIMEDOUT"}
web_1 | at null.<anonymous> (/myapp/node_modules/sails-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:213:40)
web_1 | at g (events.js:260:16)
web_1 | at emitTwo (events.js:87:13)
web_1 | at emit (events.js:172:7)
web_1 | at null.<anonymous> (/myapp/node_modules/sails-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:119:12)
web_1 | at g (events.js:260:16)
web_1 | at emitTwo (events.js:87:13)
web_1 | at emit (events.js:172:7)
web_1 | at Socket.<anonymous> (/myapp/node_modules/sails-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:154:93)
web_1 | at Socket.g (events.js:260:16)
web_1 | at emitOne (events.js:77:13)
web_1 | at Socket.emit (events.js:169:7)
web_1 | at emitErrorNT (net.js:1269:8)
web_1 | at nextTickCallbackWith2Args (node.js:511:9)
web_1 | at process._tickDomainCallback (node.js:466:17)
web_1 |
web_1 | Details: MongoError: server 13.81.244.244:27017 received an error {"name":"MongoError","message":"read ETIMEDOUT"}
此时数据库仍处于运行状态,查看日志,这一切似乎都很好:
2017-03-23T16:45:51.664+0000 I NETWORK [thread1] connection accepted from 13.81.243.59:51558 #7811 (39 connections now open)
2017-03-23T16:45:51.664+0000 I NETWORK [conn7811] received client metadata from 13.81.253.59:51558 conn7811: { driver: { name: "nodejs", version: "2.2.25" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.4.0-62-generic" }, platform: "Node.js v4.7.3, LE, mongodb-core: 2.1.9" }
2017-03-23T16:45:51.723+0000 I ACCESS [conn7811] Successfully authenticated as principal username on dbname
我的connections.js
挂钩看起来像这样:
module.exports.connections = {
sailsmongo: {
adapter : 'sails-mongo',
host : process.env.MONGODB_HOST,
port : 27017,
user : process.env.MONGODB_USERNAME,
password : process.env.MONGODB_PASSWORD,
database : process.env.MONGODB_DBNAME
},
}
和package.json
:
"sails": "~0.12.4",
"sails-mongo": "^0.12.1",
备注:
在未经证实的可能的不当行为来源中,我看到:
对此有什么想法吗?
编辑:
经过一番挖掘后,我有一个印象,看着sails / waterline的DB日志在每个查询上打开一个新连接,同时应该插入一次并保持活动状态。这可能是问题的原因。
由此,我决定在Mongoose尝试Mongoose和宾果游戏,它就像一个魅力。
我猜这是发生了Sails / Waterline的错误,虽然我不清楚如何正确地重现这个错误。
无论如何,我现在正将我的应用程序从Waterline移到Mongoose。