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

withTransaction must yield the session to avoid a deadlock on stepdown

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Sharding EMEA
    • ALL

      Any code running `withTransaction` may end up with a deadlock if the given OperationContext has a SessionId and there is a deadlock during the transaction process.

      The sequence of events leading to a deadlock is the following:

      • (A): withTransaction thread
      • (B): stepdown thread

      1. (A) checks out a SessionId
      2. (A) run withTransaction
      3. (B) step-down thread starts and an interruption error is sent to all the threads.
      4. (A) executes abortTransaction
      4. (B) step-down thread acquires RSTL lock
      5. (B) tries to checkout all sessions to kill them
      6. (B) gets blocked when trying to checkout the session of thread A
      7. (A) gets blocked trying to acquire RSTL lock to abort the transaction.

      withTransaction is a method implemented as a utility for the ShardingCatalogManager when new transactions API didn't exist.

      The new transaction API yields the session attached to the thread to avoid this scenario. So I suggest getting rid of withTransaction code and using the new transaction API instead. This is an example of implementation for the new transaction API

      This issue was discovered when the sessionId was attached to the ConfigsvrCollMod request. The sessionId was finally removed to solve quickly the bug.

            Assignee:
            backlog-server-sharding-emea [DO NOT USE] Backlog - Sharding EMEA
            Reporter:
            silvia.surroca@mongodb.com Silvia Surroca
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: