<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:44 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-755] MongoServer.Primary is not thread-safe when using a replicaset</title>
                <link>https://jira.mongodb.org/browse/CSHARP-755</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;System.InvalidOperationException: Sequence contains more than one matching element&lt;br/&gt;
   at System.Linq.Enumerable.SingleOrDefault&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source, Func`2 predicate)&lt;br/&gt;
   at MongoDB.Driver.MongoServer.get_Primary()&lt;/p&gt;

&lt;p&gt;MongoServerInstance.Primary is calling _serverProxy.Instances.SingleOrDefault(x =&amp;gt; x.IsPrimary);&lt;/p&gt;

&lt;p&gt;In our case proxy is ReplicaSetMongoServerProxy&lt;/p&gt;

&lt;p&gt;When method ProcessConnectedInstanceStateChange is called, the previously disconnected instance can come with Primary set to true.&lt;br/&gt;
In this case the previous Primary instance may not see its flag unset by ProcessConnectedPrimaryStateChange method before a call to MongoServerInstance.Primary is done =&amp;gt; Exception.&lt;/p&gt;</description>
                <environment></environment>
        <key id="78487">CSHARP-755</key>
            <summary>MongoServer.Primary is not thread-safe when using a replicaset</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="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="arnaud.tamaillon">Arnaud TAMAILLON</reporter>
                        <labels>
                    </labels>
                <created>Mon, 10 Jun 2013 17:24:43 +0000</created>
                <updated>Thu, 20 Mar 2014 14:37:05 +0000</updated>
                            <resolved>Tue, 11 Jun 2013 13:47:20 +0000</resolved>
                                    <version>1.8.1</version>
                                    <fixVersion>1.8.2</fixVersion>
                                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="369902" author="rstam" created="Fri, 28 Jun 2013 13:25:07 +0000"  >&lt;p&gt;A new fix has been implemented for &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt; that reliably keeps track of the current primary.&lt;/p&gt;

&lt;p&gt;This should resolve the race condition you were still seeing.&lt;/p&gt;</comment>
                            <comment id="358152" author="craiggwilson" created="Tue, 11 Jun 2013 22:07:03 +0000"  >&lt;p&gt;Ok, I&apos;ll reopen the issue since you are still seeing this cheery-picked into 1.8.1.  Your comment mentioned 274, which was obviously a type and why I didn&apos;t completely understand what you are saying.  We did some extensive testing against this and our tests all cleared up, but I can see the race condition that is possible, although much less likely.&lt;/p&gt;

&lt;p&gt;It comes down to the fact that we are publishing the same information we are using internally for public consumption. Immediately when the server becomes primary, this is public knowledge before we have a chance to unset the previous primary.  There isn&apos;t a whole lot we can do about this at this particular time.  It would require a massive refactoring of how things are done internally.  We have already done much of this refactoring for our 2.0 release and will not be backporting to the 1.x cycle.  I know this is a crappy answer and I apologize for it.&lt;/p&gt;

&lt;p&gt;For now, I have provided the workaround you can use (the Instances property instead of the Primary property) and filter out the Disconnected instances.  We could, arguably do that as well and I&apos;ll bring that up, but it means a change in behavior as well.&lt;/p&gt;

&lt;p&gt;If you have any suggestions on the correction for this, I&apos;m happy to listen and talk through them.  For now, I&apos;m going to leave this ticket closed re-open &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt; to identify that it is not completely fixed.&lt;/p&gt;</comment>
                            <comment id="358118" author="arnaud.tamaillon" created="Tue, 11 Jun 2013 21:37:48 +0000"  >&lt;p&gt;This has NOT been fixed by &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt;, the issue is still there with &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt; applied to the 1.8.1.&lt;br/&gt;
My report is a report based on 1.8.1 here I cherry picked &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt;, as stated in comments.&lt;/p&gt;

&lt;p&gt;If primary is not reliable, why provide it ? In production code, we cannot rely on sometimes-it-works-sometime-it-does-not API...&lt;/p&gt;</comment>
                            <comment id="357602" author="craiggwilson" created="Tue, 11 Jun 2013 13:47:20 +0000"  >&lt;p&gt;Hi Arnaud,&lt;br/&gt;
  Thanks for the bug report.  This was identified previously (&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-724&quot; title=&quot;MongoServer.IsPrimary Would Error When a Failover Occured Until the Old Primary Came Back Online&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-724&quot;&gt;&lt;del&gt;CSHARP-724&lt;/del&gt;&lt;/a&gt;) and has been fixed.  Note that it isn&apos;t a thread-safety issue, just an issue with how we handle a change in primaries.&lt;br/&gt;
  As I suggested in the other issue, I&apos;d highly suggest you not use our internal state mechanisms for cluster health monitoring, but rather issue replSetStatus commands to get the state of the cluster directly from the cluster.  Up to you, but until we release 1.9, this will be an issue for you.      &lt;br/&gt;
  You can get around this by using the Instances property and filtering what you want that way.&lt;/p&gt;

&lt;p&gt;Sorry for the trouble,&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="356930" author="arnaud.tamaillon" created="Mon, 10 Jun 2013 17:25:28 +0000"  >&lt;p&gt;Note that this issue is visible with the &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-274&quot; title=&quot;The overloads of Insert and Save in MongoCollection should match&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-274&quot;&gt;&lt;del&gt;CSHARP-274&lt;/del&gt;&lt;/a&gt; fix applied.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="71610">CSHARP-724</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></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|hrr2c7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>71736</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>