[CDRIVER-2815] Transactions options not inherited from client if empty options provided Created: 06/Sep/18  Updated: 28/Oct/23  Resolved: 06/Sep/18

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.12.0
Fix Version/s: 1.13.0

Type: Bug Priority: Major - P3
Reporter: Kevin Albertson Assignee: Kevin Albertson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-1531 Implement Transactions spec Closed

 Description   

For a transaction, readConcern, writeConcern, and readPreferences should be inherited from the client when they aren't specified in startTransaction and aren't included in the default transaction options on the session.

In libmongoc, if a session is created with empty session options, the session won't inherit the transactions readConcern, writeConcern, and readPreferences from the client.

Compilable example:

#include <mongoc/mongoc.h>
 
int
main (int argc, char *argv[])
{
   mongoc_client_t *client = NULL;
   mongoc_client_session_t *session = NULL;
   mongoc_session_opt_t *session_opts = NULL;
   mongoc_transaction_opt_t *default_txn_opts = NULL;
   bson_error_t error;
   const mongoc_session_opt_t* returned_session_opts = NULL;
   const mongoc_transaction_opt_t* returned_transaction_opts = NULL;
 
   mongoc_init ();
 
   client = mongoc_client_new ("mongodb://localhost/?w=0");
   /* construct session options and set an empty default transaction opts. */
   session_opts = mongoc_session_opts_new ();
   default_txn_opts = mongoc_transaction_opts_new ();
   mongoc_session_opts_set_default_transaction_opts (session_opts, default_txn_opts);
   session = mongoc_client_start_session (client, session_opts, &error);
 
   /* the default options should be inherited from the client but aren't */
   returned_session_opts = mongoc_client_session_get_opts (session);
   returned_transaction_opts = mongoc_session_opts_get_default_transaction_opts (returned_session_opts);
   BSON_ASSERT (mongoc_transaction_opts_get_write_concern (returned_transaction_opts) == NULL);
   /* transactions without an explicit write concern use NULL for the write concern. */
 
   mongoc_cleanup ();
   return 0;
}

mongoc_client_start_session overwrites the inherited transaction options by calling _mongoc_session_opts_copy after inheriting from the client.

The C++ driver sets a default empty transactions options when the user does not provide one, causing it to fail some spec tests.



 Comments   
Comment by Githook User [ 06/Sep/18 ]

Author:

{'name': 'Kevin Albertson', 'email': 'kevin.albertson@10gen.com', 'username': 'kevinAlbs'}

Message: CDRIVER-2815 fix client opts inheritance
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/812cd64afcbf297551e73f60f95861dcf27e60fd

Generated at Wed Feb 07 21:16:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.