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
Continuous connection losses when connecting to clusters #8059
Comments
This issue is too vague to be actionable. Realistically I won't be able to debug this without access to your codebase, but here's a couple ideas:
|
@vkarpov15 Sorry for the late reply! Here's some bullet points for your bullet points :)
Here's my connection code:
Btw, those events fire like clockwork. This is definitely not a random disconnect: |
Btw, this is being logged like this:
|
Here's a potential explanation, it looks like the reconnection happens every 20 seconds. Is your |
@vkarpov15 No, the timeout is set to 8000 ms. If that helps, I can send you the actual connection string (I'd rather send that to you directly rather than posting it here for obvious reasons ;). At the end of the day, the app isn't doing anything but connecting to said Atlas cluster as posted above in my snippet, then sitting idly (no database requests going on), so this could indeed be related to timeouts and/or keepAlive logic. Here's the full snippet:
|
Sorry for taking so long to get back to you, this seems like one of those issues that I'm unlikely to be able to help with. Below script with an Atlas instance doesn't trigger any reconnect events for me: 'use strict';
const mongoose = require('mongoose');
run().catch(err => console.log(err));
async function run() {
mongoose.connection.on("reconnected", err => {
console.log(`MongoDB reconnection success @ ${config.mongoDbUri}`);
});
await mongoose.connect('mongodb+srv://user:pass@omitted.mongodb.net/admin?retryWrites=true&w=majority', {
useNewUrlParser: true,
connectTimeoutMS: 3000,
socketTimeoutMS: 8000,
reconnectTries: 10,
reconnectInterval: 1500
});
console.log('Initial connection done');
} Output:
The only possibility I can think of right now is what is the ping time to your Atlas machine? It might be timing out because of slow internet... |
This is so weird. I managed to get around the problem by raising the A potentially related issue, that also was gone once I raised that timeout flag:
More often than not, I had a I'll try to modify your script to get a repro with my Atlas connection, and will post back here. |
Do you want to request a feature or report a bug?
This is potentially an issue, it may not be mongoose though.
What is the current behavior?
When working with a database in a docker container, I enjoy a stable connection. On the other hand, if I connect to a cluster (either MongoDB Atlas, or an Azure Cosmos DB), there's a continuous loop of disconnect/reconnect events. It doesn't matter whether I run my app locally, or in the same DataCenter that hosts the cluster. I explicitly set the
keepAlive
option, but that didn't help.This has been raised with #7452, but then closed without any resolution. Maybe the fact that I only experience this with a cluster can shed some light on this?
If the current behavior is a bug, please provide the steps to reproduce.
My app works, but it has to reconnect all the time (which affects performance and wreaks havoc in my alerting ;). To repro the issue, I just switch the connection strings to point to a MongoDB on Atlas (free tier), and then the reconnect events start to fire. When I query for health, the connection's
readyState
is rarely1
.What is the expected behavior?
Stable connection.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 5.6.7
node v11.2.0
MongoDB Atlas
Here's my connection options:
connection string: mongodb+srv://foobar-123.azure.mongodb.net/foobar?retryWrites=true&w=majority
The text was updated successfully, but these errors were encountered: