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

mongos incorrectly reports "Only the first command in a transaction may specify API parameters" error

    • Fully Compatible
    • ALL
    • Repl 2020-11-16

      The Versioned API specification requires that clients only send API version-related fields on the first command in a transaction. But even for a properly-functioning client, mongos reports an error. Here's a mongo shell repro:

      ~$ ~/Downloads/mongodb-macos-x86_64-enterprise-4.9.0-alpha-464-g21b2bc7/bin/mongo --apiVersion 1
      MongoDB shell version v4.9.0-alpha-464-g21b2bc7
      connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
      Implicit session: session { "id" : UUID("d9cc1367-6ea0-494b-a0d0-384b26b6f1fd") }
      MongoDB server version: 4.9.0-alpha-464-g21b2bc7
      
      MongoDB Enterprise mongos> session = db.getMongo().startSession()
      session { "id" : UUID("0a03fa05-795a-40bb-a9ad-05894ec979b2") }
      MongoDB Enterprise mongos> session.startTransaction()
      MongoDB Enterprise mongos> session.getDatabase("test").getCollection("test").insertOne({})
      {
      	"acknowledged" : true,
      	"insertedId" : ObjectId("5fab0124bc766c2d5df21642")
      }
      MongoDB Enterprise mongos> session.getDatabase("test").getCollection("test").insertOne({})
      uncaught exception: WriteCommandError({
      	"ok" : 0,
      	"errmsg" : "Only the first command in a transaction may specify API parameters",
      	"code" : 4937701,
      	"codeName" : "Location4937701"
      }) :
      WriteCommandError({
      	"ok" : 0,
      	"errmsg" : "Only the first command in a transaction may specify API parameters",
      	"code" : 4937701,
      	"codeName" : "Location4937701"})
      WriteCommandError@src/mongo/shell/bulk_api.js:421:48
      executeBatch@src/mongo/shell/bulk_api.js:936:23
      Bulk/this.execute@src/mongo/shell/bulk_api.js:1184:21
      DBCollection.prototype.insertOne@src/mongo/shell/crud_api.js:264:9
      

      Note that the second insert command fails.

      I've also reproduced this in a POC in Java, and confirmed that the driver is not sending any server API elements on the second command in the transaction.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: