Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4527

Reactive streams clientSession.startTransaction and then further operations is to easy to create a race condition

      I'll attach an example reproduction case, but in my case when using a session for a transaction the logs show the following:

      [main] INFO ClientSessionTest - started transaction:: txn: 166
      [main] INFO ClientSessionTest - committed transaction:: txn: 166
      [main] INFO ClientSessionTest - started transaction:: txn: 167
      [Thread-10] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:28, serverValue:320}] to localhost:27018
      [Thread-21] WARN LatchedSubscriber - Publisher failed
      com.mongodb.MongoCommandException: Command failed with error 251 (NoSuchTransaction): 'Given transaction number 167 does not match any in-progress transactions. The active transaction number is 166' on server localhost:27018. The full response is {"errorLabels": ["TransientTransactionError"], "ok": 0.0, "errmsg": "Given transaction number 167 does not match any in-progress transactions. The active transaction number is 166", "code": 251, "codeName": "NoSuchTransaction", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1646911501, "i": 430}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1646911501, "i": 421}}}
      

      So in the above case. Transaction 166, started and was committed before startTransaction 167 started but using the session with txn 167 failed.

      Steps to reproduce the issue:

      • unarchive mongodb-session.problem.tgz
      • mvn clean package
      • java -jar target/mongodb-session-problem-1.0-SNAPSHOT-jar-with-dependencies.jar &> logs.txt

      This example should also be reproducible using intellij.
      There is a sync example as well (change the pom.xml main class) which does not have this issue.

        1. ClientSessionTest.java
          5 kB
        2. LatchedSubscriber.java
          1 kB
        3. mongodb-session-problem.tgz
          2 kB

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: