Report this

What is the reason for this report?

Rebooting droplet doesn't disconnect MongoDB connection

Posted on March 12, 2016

I have two droplets running. One is running node and the other is running MongoDB. The node droplet connects to the MongoDB droplet over private networking using mongoose. If the MongoDB droplet powers off, the mongoose connection will disconnect and when the MongoDB droplet powers on, the mongoose connection will reconnect. The problem is that when the MongoDB droplet simply reboots, the mongoose connection does not disconnect. The connection does not close but is completely unusable.

var options = { server: { auto_reconnect: true, reconnectInterval: 1000, reconnectTries: Infinity, socketOptions: { keepAlive: 1, connectTimeoutMS: 1000 } } };

var db = mongoose.createConnection(‘snip’, options);



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

This looks good, what errors are you getting when trying to connect after a reboot or pull information? Have you tried increasing or decreasing the connectTimeoutMS or reconnectInterval? It’s important to understand when asking for assistance or advice to provide as much information as you can.

Currently I’m not sure how to replicate the problem you are having, so we need a bit more information. Have you tried connecting outside the node application? Perhaps it’s at the application level?

Are the reboots planned and initiated by you, unplanned, both?

If you can provide more information, a better solution may be available, but it’s a bit difficult with the limited information.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.