javascript - MongoDb drops connection after being idle for about 15 minutes -


i have node.js application connects once (to remote db) on application start , uses connection variable operations.

mongoclient.connect(mongoconnstr, connopts, function(err, db) {     ... } 

the connopts is:

var connopts = {     server: {          socketoptions: {             autoreconnect: true,              keepalive: 1          }     } }; 

so connects well, on request after being idle ~15mins, hangs ~30secs , throws following error:

/home/me/desktop/turbo/node_modules/mongodb/lib/utils.js:97     process.nexttick(function() { throw err; });                                         ^ mongoerror: server myapp.cloudapp.net:27017 sockets closed     @ null.<anonymous> (/home/me/desktop/turbo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:301:47)     @ g (events.js:199:16)     @ emit (events.js:110:17)     @ null.<anonymous> (/home/me/desktop/turbo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:101:12)     @ g (events.js:199:16)     @ emit (events.js:110:17)     @ socket.<anonymous> (/home/me/desktop/turbo/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:139:12)     @ socket.g (events.js:199:16)     @ socket.emit (events.js:107:17)     @ tcp.close (net.js:485:12) 

i know periodically pinging db should resolve problem, maybe configuration tweaks i'm missing it?

try this:

    options: {         server:{             auto_reconnect: true,             socketoptions:{                 connecttimeoutms:3600000,                 keepalive:3600000,                 sockettimeoutms:3600000             }         }     } 

i have found code here.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -