<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 06:36:09 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-77634] withTransaction must yield the session to avoid a deadlock on stepdown</title>
                <link>https://jira.mongodb.org/browse/SERVER-77634</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;Any code running `&lt;a href=&quot;https://github.com/10gen/mongo/blob/cc76b1e01aa0345bd7f06977c7365805e84d8c1e/src/mongo/db/s/config/sharding_catalog_manager.cpp#L1149-L1237&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;withTransaction&lt;/a&gt;` may end up with a deadlock if the given OperationContext has a SessionId and there is a deadlock during the transaction process.&lt;/p&gt;

&lt;p&gt;The sequence of events leading to a deadlock is the following:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;ins&gt;(A): withTransaction thread&lt;/ins&gt;&lt;/li&gt;
	&lt;li&gt;&lt;ins&gt;(B): stepdown thread&lt;/ins&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;1. (A) checks out a SessionId&lt;br/&gt;
2. (A) run withTransaction&lt;br/&gt;
3. (B) step-down thread starts and an &lt;a href=&quot;https://github.com/10gen/mongo/blob/eb548b3822e1a53224a13c7b6c96395dfb6a7afc/src/mongo/db/repl/replication_coordinator_impl.cpp#L2632&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;interruption error is sent to all the threads&lt;/a&gt;.&lt;br/&gt;
4. (A) executes &lt;a href=&quot;https://github.com/10gen/mongo/blob/cc76b1e01aa0345bd7f06977c7365805e84d8c1e/src/mongo/db/s/config/sharding_catalog_manager.cpp#L1163&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;abortTransaction&lt;/a&gt;&lt;br/&gt;
4. (B) step-down thread &lt;a href=&quot;https://github.com/10gen/mongo/blob/eb548b3822e1a53224a13c7b6c96395dfb6a7afc/src/mongo/db/repl/replication_coordinator_impl.cpp#L2634-L2635&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;acquires RSTL lock&lt;/a&gt;&lt;br/&gt;
5. (B) tries to &lt;a href=&quot;https://github.com/10gen/mongo/blob/ef97bdd7c76afbc5376358bed15e7c5325a329ad/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp#L569&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;checkout all sessions to kill them&lt;/a&gt;&lt;br/&gt;
6. (B) gets blocked when trying to checkout the session of thread A&lt;br/&gt;
7. (A) gets blocked trying to acquire RSTL lock to abort the transaction.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;withTransaction&lt;/tt&gt; is a method implemented as a utility for the &lt;tt&gt;ShardingCatalogManager&lt;/tt&gt; when new transactions API didn&apos;t exist.&lt;/p&gt;

&lt;p&gt;The new transaction API &lt;a href=&quot;https://github.com/10gen/mongo/blob/52ecfb60254c6b0627bb0ae4c69b1cb8c46adf59/src/mongo/db/transaction/transaction_api.cpp#L115&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;yields the session attached to the thread&lt;/a&gt; to avoid this scenario. So I suggest getting rid of &lt;tt&gt;withTransaction&lt;/tt&gt; code and using the new transaction API instead. &lt;a href=&quot;https://github.com/10gen/mongo/blob/cc76b1e01aa0345bd7f06977c7365805e84d8c1e/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp#L2180-L2268&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;This&lt;/a&gt; is an example of implementation for the new transaction API&lt;/p&gt;

&lt;p&gt;This issue was discovered when the sessionId was attached to the &lt;a href=&quot;https://github.com/10gen/mongo/blob/cc76b1e01aa0345bd7f06977c7365805e84d8c1e/src/mongo/db/s/config/configsvr_collmod_command.cpp&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;ConfigsvrCollMod&lt;/a&gt; request. The sessionId was finally removed to solve quickly the bug.&lt;/p&gt;</description>
                <environment></environment>
        <key id="2354829">SERVER-77634</key>
            <summary>withTransaction must yield the session to avoid a deadlock on stepdown</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="3">Duplicate</resolution>
                                        <assignee username="backlog-server-sharding-emea">[DO NOT USE] Backlog - Sharding EMEA</assignee>
                                    <reporter username="silvia.surroca@mongodb.com">Silvia Surroca</reporter>
                        <labels>
                    </labels>
                <created>Wed, 31 May 2023 15:26:09 +0000</created>
                <updated>Thu, 1 Jun 2023 01:00:55 +0000</updated>
                            <resolved>Wed, 31 May 2023 15:36:25 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="5464396" author="JIRAUSER1268536" created="Wed, 31 May 2023 15:36:25 +0000"  >&lt;p&gt;Duplicates&#160;&lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-77633&quot; title=&quot;Calling withTransaction with a checked out session may end up in a deadlock (on stepdown)&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-77633&quot;&gt;&lt;del&gt;SERVER-77633&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="2354828">SERVER-77633</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                <customfield id="customfield_12751" key="com.atlassian.jira.plugin.system.customfieldtypes:multiselect">
                        <customfieldname>Assigned Teams</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="25133"><![CDATA[Sharding EMEA]]></customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        36 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>dbeng-pm-bot</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            36 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                    <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>backlog-server-sharding-emea</customfieldvalue>
            <customfieldvalue>silvia.surroca@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i2bl9r:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i1ttvk:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|i2b7f3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>