[SERVER-68104] Can't send queries using the same transaction concurrently, NoSuchTransaction Created: 16/Jul/22 Updated: 09/Aug/22 Resolved: 09/Aug/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 5.0.6 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | yaman lakis | Assignee: | Chris Kelly |
| Resolution: | Done | Votes: | 0 |
| Labels: | Transactions, concurrency | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Operating System: | ALL |
| Steps To Reproduce: | I have attached a JS file to reproduce the issue, any MongoDB instance will work there is no special configuration required or anything, just a MongoDB replica set running. |
| Participants: |
| Description |
|
Running this operation will sometimes cause the following error NoSuchTransaction.
Now as I noticed mongodb client sends a `startTransaction` set to true on the first command executed, insert to collection A in our example, alongside a `txnNumber` and only send the the `txnNumber` value with the following commands.
I included a part of the log as a json file in the attachment that shows how first the collectionB.insert command gets executed then collectionA.insert. |
| Comments |
| Comment by Chris Kelly [ 09/Aug/22 ] | ||||||
|
Yaman, While it's correct that the first step should be startTransaction, you are trying to send requests in parallel and there is no guarantee these arrive to the server in order. MongoDB processes requests to the same session serially, as only one request runs per session, per server, at a time. This also means that parallelizing requests won't yield any benefit in a transaction. You can check out the NodeJS example in the documentation here for some more context. If you don't parallelize your inserts, you shouldn't run into this error. I'll close this issue for now, but if you encounter issues with the general process shown in the documentation, we can continue discussion here. Thanks for reaching out! Regards,
| ||||||
| Comment by yaman lakis [ 23/Jul/22 ] | ||||||
|
I tried running it again on the versions you have mentioned, MongoDB 5.0.6 and MongoDB NodeJS driver 4.8.0, and still encountered the same issue. Ran a MongoDB container using the following command:
In the container I ran mongo shell and initiated the replica set using the following configuration:
then i ran the following:
installed MongoDB NodeJS driver version 4.8.0 and ran the code in the file I attached in my issue. I got the follwoing logs: I added comments at the lines where I think they are related to the problem in the log, hope it makes things clearer. and here is the error logged by the NodeJS process Thank you for your time Chris | ||||||
| Comment by Chris Kelly [ 22/Jul/22 ] | ||||||
|
Hi Yaman, Thanks for your report - I ran your test driver on MongoDB 5.0.6 and did not observe the NoSuchTransaction message in the logs, and the inserts appeared to work. Can you explain how you are running this exactly? I used the version 4.8.0 of the mongodb node driver to run your code. Regards, |