[SERVER-37792] Strange behavior of Multi-Document Transaction Created: 28/Oct/18 Updated: 14/Nov/18 Resolved: 14/Nov/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript, Replication |
| Affects Version/s: | 4.0.2 |
| Fix Version/s: | None |
| Type: | Question | Priority: | Major - P3 |
| Reporter: | Ilya | Assignee: | Danny Hatcher (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
First of all, sorry for my english.
This is code:
In my transaction i'm trying to simulate the situation, when at first i change document as a transaction (increment field 'number' +2), and than change it not as a transaction (increment same field +3 in same doc, but i don't pass session parameter in query function). So it must cuase some write conflict, and throw some error. When i running this transaction, it waits for a 60 seconds (as i understood, max txn time), and than throw an error:
It seems, that transaction runs, can't perform update operation because of write conflict and than just waiting for txn timeout. If i'm not mistaking, this is a specific write-conflict error, so why it wait 60 seconds and throws 'NoSuchTransaction' MongoError? BUT!!! Somitimes (for example, when i add some console.log-s in transaction body) it throws another error, such as:
Here transaction don't have enough time (5ms) to lock the document. As i understood, transactions in mongo locks document not in the time, when calls session.startTransaction(), but when the operations, that are assosiated with this session and transaction, are executing.
So, what i should do with this problem? How can i handle correctly this write conflicts? Why in one situation i catch one MongoError, and in other situation - another, but both errors is caused by single reason? |
| Comments |
| Comment by Matt Broadstone [ 29/Oct/18 ] | |
|
Hi sinilya! It looks like you are not correctly passing the session into your first updateOne call above. It should read:
I think this is your primary issue, so please try it again and let's continue the discussion from there. Additionally there should be no need to await the client session above, they are created locally and synchronously. Finally, it's a bit difficult to follow your code sample, could you please make sure this accurately reflects what you are trying to run? For instance, _transactionOperations is called from within a transactionOperations async method, performTransaction is defined but never called, etc. |