Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68104

Can't send queries using the same transaction concurrently, NoSuchTransaction

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.6
    • Component/s: None
    • ALL
    • Hide

      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.

      Show
      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.

      Running this operation will sometimes cause the following error NoSuchTransaction.

       

      ...
      await Promise.all([
        collectionA.insertOne({ _id: new ObjectId() }, { session }),
        collectionB.insertOne({ _id: new ObjectId() }, { session })
      ])
      ...

       

      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 inspected the logs on mongodb and found that whenever the error happens the command with `startTransaction` set to true always comes after some other command using the same `txnNumber`, and since the transaction was not started yet the first command in the logs, insert to collection B in our example will throw an error indicating that the transaction does not exist.

       

      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.

        1. 2nd-log.json
          41 kB
        2. error.txt
          2 kB
        3. index.js
          1 kB
        4. log.json
          5 kB

            Assignee:
            chris.kelly@mongodb.com Chris Kelly
            Reporter:
            yamanlakis@gmail.com yaman lakis
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: