Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes mongoDB have reconnect issues or am i doing it wrong?
    primarykey
    data
    text
    <p>I'm using nodejs and a mongoDB - and I'm having some connection issues.</p> <p>Well, actually "wake" issues! It connects perfectly well - is super fast and I'm generally happy with the results.</p> <p><strong>My problem:</strong> If i don't use the connection for a while (i say while, because the timeframe varies 5+ mins) it seems to stall. I don't get disconnection events fired - it just hangs. </p> <p>Eventually i get a response like Error: failed to connect to [ * .mongolab.com: * ] - ( * = masked values)</p> <p>A quick restart of the app, and the connection's great again. Sometimes, if i don't restart the app, i can refresh and it reconnects happily.</p> <p>This is why i think it is "wake" issues.</p> <p><strong>Rough outline of code:</strong></p> <p>I've not included the code - I don't think it's needed. It works (apart from the connection dropout)</p> <p><strong>Things to note:</strong> There is just the one "connect" - i never close it. I never reopen.</p> <p>I'm using mongoose, socketio.</p> <pre><code>/* constants */ var mongoConnect = 'myworkingconnectionstring-includingDBname'; /* includes */ /* settings */ /* Schema */ var db = mongoose.connect(mongoConnect); /* Socketio */ io.configure(function (){ io.set('authorization', function (handshakeData, callback) { }); }); io.sockets.on('connection', function (socket) { });//sockets io.sockets.on('disconnect', function(socket) { console.log('socket disconnection') }); /* The Routing */ app.post('/login', function(req, res){ }); app.get('/invited', function(req, res){ }); app.get('/', function(req, res){ }); app.get('/logout', function(req, res){ }); app.get('/error', function(req, res){ }); server.listen(port); console.log('Listening on port '+port); db.connection.on('error', function(err) { console.log("DB connection Error: "+err); }); db.connection.on('open', function() { console.log("DB connected"); }); db.connection.on('close', function(str) { console.log("DB disconnected: "+str); }); </code></pre> <p>I have tried various configs here, like opening and closing all the time - I believe though, the general consensus is to do as i am with one open wrapping the lot. ??</p> <p>I have tried a connection tester, that keeps checking the status of the connection... even though this appears to say everthing's ok - the issue still happens.</p> <p>I have had this issue from day one. I have always hosted the MongoDB with MongoLab. The problem appears to be worse on localhost. But i still have the issue on Azure and now nodejit.su.</p> <p>As it happens everywhere - it must be me, MongoDB, or mongolab.</p> <p>Incidentally i have had a similar experience with the php driver too. (to confirm this is on nodejs though)</p> <p>It would be great for some help - even if someone just says "this is normal"</p> <p>thanks in advance</p> <p>Rob</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload