<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:44:57 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>[CSHARP-3302] SDAM deadlock when invalidating former primary</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3302</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Consider a driver connected to a replica set with the following cluster topology:&lt;/p&gt;

&lt;p&gt;Node1: primary; Node2: secondary; Node3: secondary&lt;/p&gt;

&lt;p&gt;An election takes place and Node2 is the new primary, but the driver does not know this yet. If the driver receives heartbeats from Node1 and Node2 at the same time, SDAM can deadlock as follows.&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;ProcessingofheartbeatfromNode2%28NewPrimary%29&quot;&gt;&lt;/a&gt;Processing of heartbeat from Node2 (New Primary)&lt;/h3&gt;

&lt;p&gt;The driver receives a heartbeat from Node2 (the new Primary) in &lt;tt&gt;ServerMonitor.HeartbeatAsync&lt;/tt&gt; and proceeds to process it...&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Line 389 of ServerMonitor.cs, we call &lt;tt&gt;SetDescription(newDescription&lt;/tt&gt; while holding the &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node2.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;SetDescription&lt;/tt&gt; raises the &lt;tt&gt;OnDescriptionChanged&lt;/tt&gt; event.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;OnDescriptionChanged&lt;/tt&gt; executes &lt;tt&gt;MultiServerCluster.ServerDescriptionChangedHandler&lt;/tt&gt;, which calls &lt;tt&gt;MultiServerCluster.ProcessServerDescriptionChanged&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;MultiClusterServer._updateClusterDescriptionLock&lt;/tt&gt; is acquired and held on line 298 of MultiServerCluster.cs (in &lt;tt&gt;MultiServerCluster.ProcessServerDescriptionChanged&lt;/tt&gt;).&lt;/li&gt;
	&lt;li&gt;Line 333 calls &lt;tt&gt;ProcessReplicaSetChange&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;The &lt;tt&gt;MultiClusterServer._serversLock&lt;/tt&gt; is acquired in &lt;tt&gt;ProcessReplicaSetChange&lt;/tt&gt; (line408).&lt;/li&gt;
	&lt;li&gt;The &lt;tt&gt;Server&lt;/tt&gt; object representing Node1 is invalidated (line 411).&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Server.Invalidate&lt;/tt&gt; calls &lt;tt&gt;ServerMonitor.RequestHeartbeat&lt;/tt&gt; for Node1.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;ServerMonitor.RequestHeartbeat&lt;/tt&gt; blocks trying to acquire &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Thus while processing the heartbeat from Node2 (the new primary), this thread holds:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;&lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node2&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;MultiServerCluster._updateClusterDescriptionLock&lt;/tt&gt; for the entire replset&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;MultiServerCluster._serversLock&lt;/tt&gt; for the entire replset&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;And the thread is attempting to acquire the &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1 (the former primary).&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;ProcessingofheartbeatfromNode1%28OldPrimary%29&quot;&gt;&lt;/a&gt;Processing of heartbeat from Node1 (Old Primary)&lt;/h3&gt;

&lt;p&gt;The driver receives a heartbeat from Node1 (the old Primary) in &lt;tt&gt;ServerMonitor.HeartbeatAsync&lt;/tt&gt; and proceeds to process it...&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Line 389 of ServerMonitor.cs, we call &lt;tt&gt;SetDescription(newDescription&lt;/tt&gt; while holding the &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;SetDescription&lt;/tt&gt; raises the &lt;tt&gt;OnDescriptionChanged&lt;/tt&gt; event.&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;OnDescriptionChanged&lt;/tt&gt; executes &lt;tt&gt;MultiServerCluster.ServerDescriptionChangedHandler&lt;/tt&gt;, which calls &lt;tt&gt;MultiServerCluster.ProcessServerDescriptionChanged&lt;/tt&gt;.&lt;/li&gt;
	&lt;li&gt;Line 298 of MultiServerCluster.cs (in &lt;tt&gt;MultiServerCluster.ProcessServerDescriptionChanged&lt;/tt&gt;) blocks attempting to acquire &lt;tt&gt;MultiClusterServer._updateClusterDescriptionLock&lt;/tt&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Thus while processing the heartbeat from Node1 (the old primary), this other thread holds:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;&lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;And the thread is attempting to acquire the &lt;tt&gt;MultiServerCluster._updateClusterDescriptionLock&lt;/tt&gt; for the entire replset.&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h3&gt;

&lt;p&gt;1. The thread processing the Node2 heartbeat holds the &lt;tt&gt;MultiServerCluster._updateClusterDescriptionLock&lt;/tt&gt; for the cluster but needs &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1.&lt;br/&gt;
2. The thread processing the Node1 heartbeat holds the &lt;tt&gt;ServerMonitor._lock&lt;/tt&gt; for Node1 but needs the &lt;tt&gt;MultiServerCluster._updateClusterDescriptionLock&lt;/tt&gt; for the cluster.&lt;/p&gt;

&lt;p&gt;Neither thread can make forward progress and we find ourselves in a classic deadlock.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1583652">CSHARP-3302</key>
            <summary>SDAM deadlock when invalidating former primary</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="13201">Fixed</resolution>
                                        <assignee username="boris.dogadov@mongodb.com">Boris Dogadov</assignee>
                                    <reporter username="james.kovacs@mongodb.com">James Kovacs</reporter>
                        <labels>
                            <label>apm-issue</label>
                            <label>planned-maintenance-detectable-bug</label>
                    </labels>
                <created>Fri, 8 Jan 2021 00:53:12 +0000</created>
                <updated>Sat, 28 Oct 2023 11:48:08 +0000</updated>
                            <resolved>Wed, 20 Jan 2021 21:09:14 +0000</resolved>
                                    <version>2.11.0</version>
                                    <fixVersion>2.11.6</fixVersion>
                                    <component>Connectivity</component>
                                        <votes>0</votes>
                                    <watches>13</watches>
                                                                                                                <comments>
                            <comment id="3574331" author="onyxmaster" created="Wed, 20 Jan 2021 19:45:02 +0000"  >&lt;p&gt;Excellent news, thanks for fixing this!&lt;/p&gt;</comment>
                            <comment id="3573785" author="xgen-internal-githook" created="Wed, 20 Jan 2021 16:27:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Boris&apos;, &apos;email&apos;: &apos;boris.dogadov@mongodb.com&apos;, &apos;username&apos;: &apos;BorisDog&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3302&quot; title=&quot;SDAM deadlock when invalidating former primary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3302&quot;&gt;&lt;del&gt;CSHARP-3302&lt;/del&gt;&lt;/a&gt;: Backporting compilation fix&lt;br/&gt;
Branch: v2.11.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/03015ffc30a08fe522ba0f32cdd5efc497e05e19&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/03015ffc30a08fe522ba0f32cdd5efc497e05e19&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3573784" author="xgen-internal-githook" created="Wed, 20 Jan 2021 16:27:34 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Boris&apos;, &apos;email&apos;: &apos;boris.dogadov@mongodb.com&apos;, &apos;username&apos;: &apos;BorisDog&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3302&quot; title=&quot;SDAM deadlock when invalidating former primary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3302&quot;&gt;&lt;del&gt;CSHARP-3302&lt;/del&gt;&lt;/a&gt;: Lock eliminated at ServerMonitor.RequestHeartbeat. Eliminated concurrent Cluster.RapidHeartbeatTimerCallback invocations.&lt;br/&gt;
Branch: v2.11.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/2d9fe31155f6cd3e2ec5576612c80ab3c7325a08&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/2d9fe31155f6cd3e2ec5576612c80ab3c7325a08&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="3572399" author="xgen-internal-githook" created="Tue, 19 Jan 2021 21:46:01 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;Boris&apos;, &apos;email&apos;: &apos;boris.dogadov@mongodb.com&apos;, &apos;username&apos;: &apos;BorisDog&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3302&quot; title=&quot;SDAM deadlock when invalidating former primary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3302&quot;&gt;&lt;del&gt;CSHARP-3302&lt;/del&gt;&lt;/a&gt;: Lock eliminated at ServerMonitor.RequestHeartbeat. Eliminated concurrent Cluster.RapidHeartbeatTimerCallback invocations.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/a013eb01df35ecce863445987ead1b76221b3845&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/a013eb01df35ecce863445987ead1b76221b3845&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="1585501">CSHARP-3307</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                    <customfield id="customfield_13552" key="com.go2group.jira.plugin.crm:crm_generic_field">
                        <customfieldname>Case</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[[5002K00000rzo5IQAQ, 5002K00000ryv9yQAA, 5002K00000uENtZQAW, 5002K00000uEEefQAG, 5002K00000tSXS5QAO, 5002K00000sbHWkQAM, 5002K00000s0ThUQAU, 5002K00000xExcSQAS]]]></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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hr483z:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>