Skip to content
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

startSession() hangs #8239

Closed
lahiruchandima opened this issue Oct 11, 2019 · 4 comments
Closed

startSession() hangs #8239

lahiruchandima opened this issue Oct 11, 2019 · 4 comments
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@lahiruchandima
Copy link

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. I call mongoose.startSession() to start the transaction. Very infrequently, this mongoose.startSession() call hangs indefinitely.

I noticed that there had been a primary node failover in the cluster at the time at which the issue occurred, so this could be caused due to not correctly identifying the failover. I do not have capability to manually do a failover, so I am unable to try to reproduce this by doing failovers.

Following is the code I use to start session.

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:mypassword@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);
    }
});

Can this be an issue in Mongoose?

@endze1t
Copy link

endze1t commented Oct 16, 2019

I'm currently facing the exact same issue.

Starting my app normally with 3 Replicas. Transactions works perfectly. I just shutdown on 1 Replica. Transactions doesn't work anymore, till I restart mongoose and starting the replica again.

@vkarpov15 vkarpov15 added this to the 5.7.6 milestone Oct 17, 2019
@vkarpov15 vkarpov15 added the needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue label Oct 17, 2019
@vkarpov15
Copy link
Collaborator

@lahiruchandima @endbay what version of Mongoose are you using?

@vkarpov15 vkarpov15 removed this from the 5.7.6 milestone Oct 19, 2019
@vkarpov15 vkarpov15 added needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels Oct 19, 2019
@endze1t
Copy link

endze1t commented Oct 19, 2019

Newest but I found out, it was probably the MongoDB bug with useUnifiedTopology: true here:

https://jira.mongodb.org/browse/NODE-2231?jql=text%20~%20%22useUnifiedTopology%22

Since I've using old deprecated useUnifiedTopology, everything is working without issues anymore.

@marvellouschandan
Copy link

In my case, I was creating session the wrong way like you did.

mongoose.startSession()

Rather you should create the session with the mongo connection you created.

I have written a stackoverflow answer after I was able to solve my issue. Please refer if you are still stuck.
https://stackoverflow.com/a/77698358/9148833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants