[CDRIVER-3366] txn_opts_cleanup should reset max_commit_time_ms Created: 11/Sep/19  Updated: 28/Oct/23  Resolved: 06/Nov/19

Status: Closed
Project: C Driver
Component/s: Transactions
Affects Version/s: 1.15.0
Fix Version/s: 1.15.2

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Andreas Braun
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CDRIVER-3143 Allow applications to set maxTimeMS f... Closed

 Description   

txn_opts_cleanup is called from the following places:

  • _mongoc_client_session_append_txn when the state is COMMITTED, COMMITTED_EMPTY, or ABORTED. The state will be reset to NONE and the options reset.
  • mongoc_client_session_destroy, when the session itself is freed

txn_opts_set is called from the following places:

  • _mongoc_client_session_new when creating a new client session. Opts are set first from the client and then from explicit default options (if any) passed to start_session
  • mongoc_client_session_start_transaction() when starting a transaction. Opts are first set from the session's default options and then from explicit opts (if any) passed to start_transaction

txn_opts_set only assigns RC, WC, and RP if they are non-null. max_commit_time_ms is only assigned if it is not DEFAULT_MAX_COMMIT_TIME_MS, which is defined as zero. Since memory is zero-allocated, the initial options struct is correctly initialized with the default value for max_commit_time_ms.

Since txn_opts_cleanup never resets max_commit_time_ms, I think it's possible for one transaction's max_commit_time_ms to bleed over to the next. Consider a case where one transaction specifies a non-zero max_commit_time_ms. That transaction ends (either committing or aborting). The next transaction starts and if the default transaction opts had no max_commit_time_ms (i.e. the default), txn_opts_set will leave the field as-is. I believe the correct fix for this is to have txn_opts_cleanup also reset max_commit_time_ms as it does the RC, WC, and RP pointers. It shouldn't be too hard to create a regression test for this as well.



 Comments   
Comment by Githook User [ 06/Nov/19 ]

Author:

{'username': 'alcaeus', 'email': 'git@alcaeus.org', 'name': 'Andreas Braun'}

Message: CDRIVER-3366 reset max_commit_time_ms in txn_opts_cleanup
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/e995f437c3f14a443af35187d064d05124cefe82

Comment by Githook User [ 06/Nov/19 ]

Author:

{'name': 'Andreas Braun', 'username': 'alcaeus', 'email': 'git@alcaeus.org'}

Message: CDRIVER-3366 reset max_commit_time_ms in txn_opts_cleanup
Branch: r1.15
https://github.com/mongodb/mongo-c-driver/commit/258fbe3db85c86d57e03ec0660e1ac78c6ddf665

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