Hi,
I am using mongoose to connect to my Mongodb Atlas cluster through my nodejs server.
There is a certain operation which is done as a transaction. Mongoose needs mongoose.startSession() to be called to start a transaction. Very infrequently, this mongoose.startSession() call hangs indefinitely. There is no certain way to reproduce this.
log.info('starting session');
const mongoSession = await mongoose.startSession();
log.info('session started');
In above code, starting session. gets logged, but session started doesn't get logged when issue occurs.
I connect to the db like below:
const dburl = 'mongodb+srv://myuser:mypas...@myapp.mongodb.net/mydb?retryWrites=true&w=majority';
mongoose.connect(dburl, {useNewUrlParser: true}, err => {
if (err) {
log.warn('Error occurred when connecting to database. ' + err);
}
});
What could be the reason for this? Could this be due to something wrong with the database? Is there any way I can further troubleshoot this?
Thanks in advance
Hi Lahiru,
Some quick questions:
Best regards,
Kevin
Hi Lahiru,
Some quick questions:
- Do you see any error message? If not, is it possible to catch the promise rejection?
- What do you mean by “no certain way to reproduce this”? Does it mean that most of the time the code works without issues, and sometimes it just doesn’t work? Is there any pattern you can think of?
- In the event that it “hangs”, the database connection was established correctly, right?
- What is your Mongoose version, and what is your Atlas deployment type (M0, M2, etc.)
--
Best regards,
Kevin
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/53e3886c-79b2-4833-89df-45bf0ea79aa4%40googlegroups.com.
Hi Lahiru,
I found that there had been a primary node restart around the last time this issue occurred, so there can be a relationship with node failovers.
This might be a hint. In your connection string:
const dburl = ‘mongodb+srv://myuser:mypas...@myapp.mongodb.net/mydb?retryWrites=true&w=majority‘;
I noticed that you don’t have the replicaSet option set (see Connection String URI Format). It’s possible that the stall happens because it just doesn’t know that it’s connected to a replica set and thus it doesn’t know that it needs to handle failovers.
Could you try adding the parameter replicaSet=<your replica set name> to the connection string and try again? Note that in Atlas M10 and above you have a “Test Failover” button that you can use to test your app for handling failovers.
Best regards,
Kevin
replicaSet
and
authSource
options. I checked the TXT record of the domain in my url and it includes the replicaSet option: (
authSource=admin&replicaSet=myapp-shard-0
)--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/96614ce6-436f-496d-8e0d-3321d55dba63%40googlegroups.com.
Hi Lahiru,
Ah you’re right. In that case it should be able to pick up that it’s a replica set and act accordingly during failovers. That is, unless something in Mongoose is preventing the failovers from being detected/operated correctly. I think it’s very unlikely this is a bug from Atlas/MongoDB side. What is your Mongoose version? And have you tried the “Test Failover” button to see if you can reproduce this reliably?
Best regards,
Kevin
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/f4605742-9d4e-4c2e-8247-0080707d3133%40googlegroups.com.