Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5644

Address potential TimeoutContext sharing issues in transactions

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 5.2.0
    • Component/s: CSOT
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      A potential issue has been identified in the handling of TimeoutContext within ClientSession. The method TimeoutContext#createTimeoutContext currently reuses the existing TimeoutContext from the session when operations begin execution. Given that TimeoutContext is mutable and stateful, and it overrides the maxTime behavior for each operation executed within a transaction, this reuse might lead to unintended interactions among concurrent operations. This scenario could potentially affect the correct execution of operations by allowing maxTime settings from one operation to unintentionally influence another due to the shared TimeoutContext.

      Expected behavior: Each operation within a transaction should operate with an isolated TimeoutContext, ensuring that maxTime settings do not interfere with other operations.

      Observed concern: TimeoutContext is currently reused across operations, potentially leading to conflicts and unpredictable behavior in the execution of concurrent operations within a transaction.

      Suggested fix: Modify TimeoutContext#createTimeoutContext to always create a new TimeoutContext for each operation when a ClientSession already has an existing context (it exists only when in transacation). This new context should be a copy of the existing one but should not reset the remaining timeout. This approach would ensure that each operation maintains its own independent timeout settings, preventing unintended cross-operation influences.

      Impact: Addressing this potential issue would enhance the reliability and predictability of timeout management in the driver, particularly in scenarios involving transactions with multiple concurrent operations.

            Assignee:
            Unassigned Unassigned
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: