-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
topology was destroyed #4890
Comments
hey @TrejGun I get this sometimes too, usually during my tests because sometimes i forget to close my db connections in my tests. Couple of questions: Can you give us more info on what environment this is happening in? Can you paste your mongoose configuration and how the connection is established, any options you pass? |
on my localhost and using pm2, webpack, babel, react with hot reloading mongoose.Promise = bluebird.Promise;
const url = "mongodb://localhost/dbName";
const options = {
server: {
socketOptions: {
keepalive: 1
}
}
}
const db = mongoose.createConnection();
db.on("disconnected", () => {
db.open(url, Object.assign({}, options, {promiseLibrary: bluebird}));
});
db.on("error", error => {
db.close();
});
db.open(url, Object.assign({}, options, {promiseLibrary: bluebird})); |
Ok thanks. I was gonna ask if you were running this behind a load balancer but it looks like your db lives on the same instance as your app. Do you have error logs for your application and can you cross reference them for when your db errors and your app issues I wonder if your db is closing while a db call is ongoing or about to happen in your app. For instance, are there any db operations that happen on application startup? Another theory is that your db error event listener is never triggered and the db maintains an open connection if an error crashes your server. I generally like to handle db connections in a Either way, this might be difficult to debug unless you have some logs in place. |
probably you are right this can be caused by webpack's --watch option which restarts dev server at any time, ie while db call is ongoing not sure how to handle this gracefully, may be it make sense to add here are some more errors
|
Ah I was under the impression this was happening in your production env too. Is this only in dev mode when you run webpack dev server? Anyway, you can try increasing the connection timeout, that might work. But this is kind of outside mongoose's scope to handle since throwing an error when you try to make a db call when the db isn't accessible is probably a good thing and it is actually a mongo node driver issue moreso than it is a mongoose issue. That being said, you could probably easily replicate the bug to confirm by making a query that is guaranteed to take a few seconds and then change some server side code that would force a server restart. If you can make it reproducible, I'd recommend you open an issue on https://github.com/mongodb/node-mongodb-native. Sorry if this seems like a cop out but mongoose doesn't do much in the way of db connection besides simply exposing the underlying driver connection to the db. |
@varunjayaraman yes sure, just tell me please who is responsible for reconnection? because this is the main issue, after that |
So if mongoose reports a connection error then it's your job to try to reconnect. Mongoose will try to reconnect on its own but if it gets Topology was destroyed then that's up to you |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I'm doing nothing special but having this error at list once a day
Please mention your node.js, mongoose and MongoDB version.
mongoose 4.7.6
➜ node -v
v7.0.0
➜ npm -v
4.0.2
➜ mongo --version
MongoDB shell version v3.4.0
The text was updated successfully, but these errors were encountered: