gpt4 book ai didi

node.js - Mongoose 超时并抛出异常

转载 作者:太空宇宙 更新时间:2023-11-04 02:39:45 25 4
gpt4 key购买 nike

当node.js服务器不活动一段时间时,它会崩溃并出现以下异常:

events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [------] at null. (/Users/tomi/Documents/Platforms/Databox/Sources/Web/server/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:636:74)
at EventEmitter.emit (events.js:106:17)
at null. (/Users/tomi/Documents/Platforms/Databox/Sources/Web/server/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:139:15)
at EventEmitter.emit (events.js:98:17)
at Socket. (/Users/tomi/Documents/Platforms/Databox/Sources/Web/server/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:476:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:415:13)

这就是我初始化连接的方式:

function connect(uri, poolsize, callback) {

var options = {
db: { native_parser: false, retryMiliSeconds: 5000, numberOfRetries: 360000 },
server: { poolSize: poolsize, socketOptions: { keepAlive: 1, connectTimeoutMS: 5000 }, auto_reconnect: true }
};
this.connection = mongoose.connect(uri, options).connection;

var addEvents = function (obj) {
obj.on('connected', function () {
console.log('Connected to database');
//connectionPoolStats.logConnectionPoolStats();
});
obj.on('disconnected', function () {
console.log('Disconnected from database');
});
obj.on('close', function () {
console.log('Connection to database closed');
});
};
addEvents(this.connection);

if (callback) {
callback();
}

};

连接只会抛出异常并且不会重新初始化;(

有什么线索吗?

最佳答案

您在哪个版本的 Mongoose 中看到了这个?

请使用今天发布的新版本进行测试:npm install mongoose@3.6.17

如果您仍然看到此问题,请open a ticket .

关于node.js - Mongoose 超时并抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17809285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com