猫鼬超时并引发异常 [英] Mongoose times out and throws exception

查看:62
本文介绍了猫鼬超时并引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当node.js服务器处于非活动状态一段时间后,它会崩溃,并出现以下异常:

When node.js server is inactive for some time, it crashes with following exception:

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)

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

This is how I init the connection:

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();
}

};

该连接只会引发异常,而不会重新初始化;(

The connection just throws exception and never reinitializes ;(

有任何线索吗?

推荐答案

您看到的是哪个版本的猫鼬?

With which version of mongoose are you seeing this?

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

Please test with the new release available today: npm install mongoose@3.6.17.

如果您仍然遇到此问题,请打开票证.

If you continue to see this issue, please open a ticket.

这篇关于猫鼬超时并引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆