[SERVER-52748] mongos incorrectly reports "Only the first command in a transaction may specify API parameters" error Created: 10/Nov/20  Updated: 29/Oct/23  Resolved: 11/Nov/20

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.9.0-rc0

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Server version 4.9.0-alpha-464-g21b2bc7, which was downloaded from http://downloads.10gen.com/osx/mongodb-macos-x86_64-enterprise-latest.tgz


Issue Links:
Problem/Incident
is caused by SERVER-50375 Ensure mongos forwards API parameters... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Repl 2020-11-16
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 11/Nov/20 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-52748 Fix txn-continuing cmds with API params via mongos
Branch: master
https://github.com/mongodb/mongo/commit/cb0deac8d70bd1927546f751526441daaabd55ec

Comment by A. Jesse Jiryu Davis [ 11/Nov/20 ]

Cause:

1. A client starts a transaction with a command that includes API parameters
2. mongos correctly forwards these API parameters to shards along with the transaction-starting command
3. A client sends a transaction-continuing command to mongos, correctly omitting API params
4. mongos correctly loads the previous API params from the TransactionParticipant
5. mongos wrongly forwards these recalled API params to shards along with the transaction-continuing command
6. The shards correctly reject the command because API params are not allowed in transaction-continuing commands

mongos shouldn't include the recalled API params with transaction-continuing commands it sends to shards.

Generated at Thu Feb 08 05:28:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.