2013-07-23 63 views
1

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

};

连接只是抛出异常,从不重新初始化;(

任何线索

回答