question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting server selection timeout error when maintenance happend on mongodb(mongodb atlas) server

See original GitHub issue

Hi,

I am using mongoose api to connect to mongodb. When any maintenance happend on mongodb i am getting server selection timeout error on running application.

mongodb - 4.0.17 mongoose - 5.7.6 node - 8.12.0

mongoose connection code -

mongoose.Promise = global.Promise;

mongoose.connection.on('connected', function () {
    console.log("MongoDB event connected");
});

mongoose.connection.once('open', function () {
    console.log('Connection to mongodb database is open');
});

mongoose.connection.on('disconnected', function () {
    console.log("MongoDB event disconnected");
});

mongoose.connection.on('reconnected', function () {
    console.log('MongoDB event reconnected');
});

mongoose.connection.on('error', function (err) {
    console.log('MongoDB event error: ' + err);
});
mongoUri = 'mongodb+srv://<userid>:<password>@cluster0-OMITTED.mongodb.net/mydb?retryWrites=true&w=majority';
mongoose.connect(mongoUri , {
    useUnifiedTopology: true,
    useNewUrlParser: true,
    useFindAndModify: false, //to remove findAndModify deprication warming
    autoIndex: false, //false
    reconnectTries: Number.MAX_VALUE,
    reconnectInterval: 500, //In milliseconds
    poolSize: 80,
    socketTimeoutMS: 60000, //Close sockets after 45 seconds of inactivity
}).then(() => {
    console.log("Database connected successfully");
}).catch(err => {
    console.log('App starting error:' + err.stack);
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
ztrangecommented, Apr 23, 2020

I can confirm that v5.9.10 no longer fails.

I reproduced it with mongo atlas M10 cluster first with mongoose v5.8.11 and got the NotMaster error 3 min after i used the Restart primary button to test failover on Atlas. I ran the test again using 5.9.10 and the failover ended without interrupting writes. My test script was constantly writing to db.

0reactions
vkarpov15commented, Apr 27, 2020

If you’re experiencing a similar issue, please open a new issue and follow the issue template.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MongoDB connection error: MongoTimeoutError: Server ...
Please Check your Password, Username OR IP configuration. Mostly "Server selection timed out after 30000 ms at Timeout.
Read more >
Server selection error: server selection timeout, current topology
I'm trying to connect to via my code in golang. I am using the mongo-driver module. I am able to connect to instance:...
Read more >
Understanding MongoDB Client Timeout Options - ScaleGrid
Server selection timeout is the number of milliseconds the mongo driver will wait to select a server for an operation before giving up...
Read more >
Mongoose v6.8.2: Connecting to MongoDB
Buffering; Error Handling; Options; Connection String Options; Connection Events; A note about keepAlive; Server Selection; Replica Set Connections ...
Read more >
server selection timed out after 30000 ms - You.com
I got the Error MongooseServerSelectionError: Server selection timed out after 30000 ms. I am using MongoDB Atlas and tried to add the IP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found