Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-98778

Coverity analysis defect 163833: Check of thread-shared field evades lock acquisition

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Cluster Scalability
    • ALL
    • Cluster Scalability 2024-12-23

      Check of thread-shared field evades lock acquisition

      The data guarded by this critical section may be read while in an inconsistent state or modified by multiple racing threads. Checking the value of a thread-shared field outside of a locked region to determine if a locked operation involving that thread shared field has completed.
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:328: LOCK_EVASION 163833 Thread1 acquires lock "mongo::TransactionCoordinatorService._mutex".
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:334: LOCK_EVASION 163833 Thread1 uses the value read from field "_initTerm" in the condition "this->_initTerm >= term". It sees that the condition is false. Control is switched to Thread2.
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:328: LOCK_EVASION 163833 Thread2 acquires lock "mongo::TransactionCoordinatorService._mutex".
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:334: LOCK_EVASION 163833 Thread2 uses the value read from field "_initTerm" in the condition "this->_initTerm >= term". It sees that the condition is false.
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:353: LOCK_EVASION 163833 Thread2 sets "_initTerm" to a new value. Note that this write can be reordered at runtime to occur before instructions that do not access this field, even into (but not to the other side of) preceding locked regions. Control is switched back to Thread1.
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:348: LOCK_EVASION 163833 Thread1 acquires lock "std::unique_lock<std::mutex>._M_device".
      /data/bazel_cache/1de52aaeb35278243ca29a4785ce7969/execroot/_main_/src/mongo/db/s/transaction_coordinator_service.cpp:353: LOCK_EVASION 163833 Thread1 sets "_initTerm" to a new value. Now the two threads have an inconsistent view of "_initTerm" and updates to fields correlated with "_initTerm" may be lost.

            Assignee:
            kruti.shah@mongodb.com Kruti Shah
            Reporter:
            xgen-internal-coverity Coverity Collector User
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: