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

Documents Not Reset During Transient Transaction Errors #8740

Closed
makinde opened this issue Mar 28, 2020 · 3 comments
Closed

Documents Not Reset During Transient Transaction Errors #8740

makinde opened this issue Mar 28, 2020 · 3 comments

Comments

@makinde
Copy link
Contributor

makinde commented Mar 28, 2020

Do you want to request a feature or report a bug?
Bug (or very unexpected behavior)

What is the current behavior?

// Find docs
const group = await Group.findById(id).exec();
const profile = await Profile.findById(id2).exec();

// edit docs
group.name = 'foo';
profile.name = 'bar';

// Save the documents
await session.withTransaction(() => {
  await group.save({ session });
  await profile.save({ session });
});

When the second save encounters a TransientTransactionErrors, withTransaction retries the entire lambda. The problem is that while the first save gets rolled back, the group document still thinks that it has been saved. So the second time around, group.save() will think that there's nothing to save and will basically be a no-op. This is very hard to understand and debug.

What is the expected behavior?
Ideal would be that if the transaction fails, the state of the document is rolled back as well. This may be difficult.

Perhaps we can get away with talking about it more in the docs for transactions. I believe what is required right now is to move the entire code block above into the withTransaction lambda (the find, modification, and save). That way the documents are reset if the transaction fails.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.14.0
Mongoose: 5.9.6
MongoDB: 4.2.3

@AbdelrahmanHafez
Copy link
Collaborator

Is this the same behavior you're looking for? #8380
If so, let me know so we can close this and follow up on the issue above.

@makinde
Copy link
Contributor Author

makinde commented Mar 29, 2020

Ah yes, that looks like a very similar issue. In that issue, you’d want to reset the doc that had the error. In this issue, you want to reset the object that had its own write “succeed”, but another action in the transaction failed. Depending on how the fix is implemented, it could be the same or a different fix.

@makinde
Copy link
Contributor Author

makinde commented Mar 29, 2020

Thanks for the quick triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants