Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2815

Transactions options not inherited from client if empty options provided

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.12.0
    • Fix Version/s: 1.13.0
    • Component/s: libmongoc
    • Labels:
      None

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kevin.albertson Kevin Albertson
              Reporter:
              kevin.albertson Kevin Albertson
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: