[SERVER-77634] withTransaction must yield the session to avoid a deadlock on stepdown Created: 31/May/23  Updated: 01/Jun/23  Resolved: 31/May/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Silvia Surroca Assignee: [DO NOT USE] Backlog - Sharding EMEA
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-77633 Calling withTransaction with a checke... Closed
Assigned Teams:
Sharding EMEA
Operating System: ALL
Participants:

 Description   

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.



 Comments   
Comment by Silvia Surroca [ 31/May/23 ]

Duplicates SERVER-77633

Generated at Thu Feb 08 06:36:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.