-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
{ useUnifiedTopology: true } leads to MongoDB connection error: MongoTimeoutError: Server selection timed out after 30000 ms #8180
Comments
What docker image do you use? Also, do you have a stack trace for the 'Server selection timed out' message? |
Hey, just poking in here to report that I had the same issue. I myself am not using Docker or any vm. Also to note is that this doesn't seem to happen all the time, however today I was unable to retreive any of my data due to timeouts (30k), and the issue was immediately resolved when removing the I'm connecting to an Atlas cluster. Mongoose is 5.7.1 Connecting like this: mongoose.createConnection(uri,
{
useCreateIndex: true,
useNewUrlParser: true,
useUnifiedTopology: true, // commented out currently
dbName: db_name
}); The model is created like this: import mongoose from 'mongoose';
import * as db_conns from '../db-connections'; // this is an object of connections generated via createConnection
// ... schema definition, for a model called 'article' from a collection called 'article'
// `site_content` is the name of a connection
export default db_conns.connections.site_content.model(`article`, schema, `article`); Then it's fetched like this: // ...
await query.model.find(query_expr).limit(30); // query_expr can change, however even an empty expression ({}) will cause the same issue
// ... The |
@vkarpov15 I'm using the latest |
I am also getting the same error after adding the { useUnifiedTopology: true } , although the error is randomly occuring. There is something definitely wrong. I am using the latest mongo image. |
mongoose |
Any solutions? Even I am facing this issue now... |
I have the same issue. I'm a junior programmer and it's my first time using nodejs-express-graphql-mongoose-mongodbAtlas. (node:9392) UnhandledPromiseRejectionWarning: MongoTimeoutError: Server selection timed out after 30000 ms Error: read ECONNRESET |
We're also getting the same error on our production server after enabling
|
I started to encounter another problem now When I searched for this warning I came across this mongoDB document It states both the errors Since I am encountering this error on my live server I have no choice but to set { useUnifiedTopology: false }. I hope someone from the community can focus on this issue and resolve it or provide some suggestions to resolve it. |
I am also getting both errors (Server selection timed out after 30000 ms and MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11) when using useUnifiedTopology so this is happening to everyone that uses this option I guess. |
I've tried to repro this, but I haven't been able to repro. I tried a few options:
I have yet to see this error message in any case. Can you please modify the below script to demonstrate this issue? 'use strict';
const mongoose = require('mongoose');
run().catch(err => console.log(err));
async function run() {
mongoose.set('useUnifiedTopology', true);
mongoose.set('useNewUrlParser', true);
await mongoose.connect('mongodb://localhost:27017/test');
const Model = mongoose.model('Test', new mongoose.Schema({ name: String }));
console.log('Query...');
await Model.findOne();
console.log('Done');
} Or at least provide some information about what version of Mongoose you're using; whether you're using a standalone server, replica set, or sharded cluster; and whether you're using Mongoose directly or via another npm module? |
I'm fairly convinced this is not an issue with mongoose, but with Mongo itself. @vkarpov15, please see my comment, I outlined my environment there. I'm using mongoose directly. |
@vkarpov15 for me this issue appears randomly every 2-3 days when the server is running so even if I provide you the code you will have to monitor the server continuously. |
Has anyone got around this issue? |
You can just not use this flag for the time being. Mongo will warn you that it will be disabled in future or something but for the time being it seems to totally solve this issue. |
Can confirm that commenting |
@rpedroni Sadly, it doesn't for us... |
Also happening here. Our production server responds with the bellow message. I gues I will comment useUnifiedTopology for now MongoDB Connection Options
Server Log
|
We are having this issue as well and we do not use mongoose. It appears to be a problem with the MongoDB driver for Node.js itself. The issue has also been reported over here https://jira.mongodb.org/browse/NODE-2249
|
@zhenwan this looks like an issue downloading the |
I was able to reproduce the error and check if it was solved with the v3.3.4-rc0 driver using the following setup:
The results of this test were as follows: ✅ Mongodb Node.js
❌ Mongodb Node.js
So it seems to work with
|
@mbroadst yes, deleting package-lock.json solved my missing file issue. But I still get the error: |
@zhenwan it looks like it might be related to not being able to connect to your cluster on initial connect. Also your backtrace to Can you please open a new jira ticket so we can triage your particular case. It looks like we'll need more detail than what you've pasted here. Thank you! |
@mbroadst
In my case, I'm using
my connection parameters as follow
below is my environment parameters
Thanks in advance update |
Another confirmation here, from someone using mongoose directly, that @mbroadst thank you for the update from MongoDB's end. Excuse my ignorance, but will the aforementioned fix in mongodb v3.3.4-rc0 cascade down to mongoose at some point? Slightly uncomfortable with the idea of embracing deprecated features as a workaround in a prod environment. |
@mmmmoj similar to @zhenwan's question above, your stack trace seems to indicate you are not in fact running v3.3.4-rc0. Maybe try removing your |
@bigsee (man GitHub does not like autocompleting your name!) Glad to hear it works for you, and you're welcome for the update - our community is very important to us. I'll let @vkarpov15 speak for the timing of the release, but we work closely and I'm sure he's interested in fixing this for y'all :) |
@mbroadst ha! sorry for the awkward name! it turns out I might have spoken too soon, perhaps given the random nature of the error appearing. On a cold start of my app, along with the expected deprecation warning, I now see this slightly scarier error in the logs:
It used to be |
@bigsee that error would indicate that you are not using the unified topology. Please enable it by passing |
@mbroadst that's correct, which I believe is the point of this issue. Apologies if I'm wrong on that. When I pass As with @vkarpov15 and others above, I have not been able to reproduce this issue consistently. The error happens a few times a day resulting in 502 and horrible UX from time to time errors. It seems to be a new issue. As reported above, the workaround of setting |
@bigsee the The point of this issue is that people were following the guidance to use the unified topology, and when they did they were experiencing spurious timeout errors. I should also say: this version will not prevent all timeout errors. That error is being caused by the driver's inability to do an initial connect to a cluster, which would indicate some sort of configuration (connection string) or network error on your part. With the unified topology this will show up as a |
@mbroadst I didn't mean to suggest that the
Perhaps, as you suggest, this is correlation rather than causation. Just seemed like a smoking gun to me. At least the app is not crashing now. I'm just worried about leaving an option that is deprecated. |
@bigsee Ah! Sorry, I misread your original comment to mean that you were confirming that the |
This is my first trial on Mongodb and I'm having this error. read through the comments and changed my db to v3.3.4-rc0 and it didn't still fix the error DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. |
@Syfon01 the error you are experiencing is because of some sort of configuration error, the driver is using the legacy topology and failing to make its initial connection to a cluster after a default of 10s. Please check your connection string and network configuration and verify that you are able to connect to the cluster (perhaps with the |
For people who are having this issue , if you are using Mongo Atlas Cloud Instance , Please see if you are having your IP address specified correctly in the Network Access tab. I had the issue and it seems that since my ISP gives out New IPs everytime (DHCP) i reconnect to the network , Mongo Atlas was only white listing the previously specified IP address. Hope this helps someone. |
update - doesn't work I was able to solve this issue by changing the structure of my code, specifically the callback as follows:
|
@mtn2bay that doesn't make any sense you basically used the callback function instead of the promise, the result is still one and the same, the only difference is that in the callback function you get both the connection and the error in the callback function which you're not logging instead of relying on .then and .catch, so your function is logging connected to db and starting the app either way even if there's an error. try this instead
|
@khaledosman thank you for the correction. You are right, I was just ignoring the error rather than addressing it. I actually had an issue with my db path. |
i was facing the same issue, i updated mongoose npm package from 5.6.9 to 5.7.6 and the issue vanished. |
solved my issue |
I do not know how that solved a problem, but I downloaded Compass and connected it to database, just copied the link. Once it got connected, the error was gone. Topology is still true in my code. Maybe it configured some options with Compass that were not right with usual mongodb installation. Now I can connect without Compass and all seems to work, just did it once in the beginning. |
I got the same issue and thanks to this forum, got through by commenting useUnifiedTopology setting. However then I uncommented this setting, but now it still works just fine... quite confused... |
Mongoose v5.7.11 uses the newly release MongoDB driver 3.3.4, so I'm going to close this issue. If you're getting a similar error message, please open up a new issue and follow the issue template. |
Do you want to request a feature or report a bug?
A bug.
What is the current behavior?
After updating to Mongoose 5.7.1, the following warning appeared:
I added
useUnifiedTopology: true
to my mongoose config object as suggested by the message, even though I'm not using MongoDB replica set or sharded cluster. Here is how I configure and connect using mongoose:and here is where I used this
mongo.options
object:The warning is gone but the issue is that mongoose is now no longer able to connect:
Here is how I run MongoDB using docker during development:
If the current behavior is a bug, please provide the steps to reproduce.
See above
What is the expected behavior?
Mongoose should remove the deprecation warning and run fine when using
useUnifiedTopology: true
as mongoose suggests.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: v10.16.2
Mongoose: 5.7.1 (latest)
MongoDB: db version v4.2.0
Related issues:
The text was updated successfully, but these errors were encountered: