<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:30 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-671] Driver does not automatically reconnect to secondary</title>
                <link>https://jira.mongodb.org/browse/CSHARP-671</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Under the following conditions the client is unable to automatically re-connect to a secondary without restarting IIS:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;The primary is down&lt;/li&gt;
	&lt;li&gt;The client is connected to the secondary&lt;/li&gt;
	&lt;li&gt;The secondary goes down&lt;/li&gt;
	&lt;li&gt;The secondary comes back up&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;In an attempt to recover from this I tried .Reconnect(), but the client is still unable to reconnect to the server.&lt;/p&gt;

&lt;p&gt;Dug into the code a bit and it appears that as soon as the secondary starts up again and the client notices and apparently erroneously removes the secondary from the list of instances. Because the primary is down and the primary is now the only remaining instance the client knows about it will not reconnect.&lt;/p&gt;

&lt;p&gt;If I alter IsValidInstance in ReplicaSetMongoServerProxy to skip the &apos;instance.InstanceType != MongoServerInstanceType.ReplicaSetMember&apos; check it appears to behave as expected.&lt;/p&gt;

&lt;p&gt;I&apos;ve tried lots of different connection strings and they do not appear to alter the behavior. Here in an example if it is helpful: mongodb://user:password@localhost,tools/DatabaseName?safe=true&amp;amp;readPreference=primaryPreferred&lt;/p&gt;

&lt;p&gt;I don&apos;t understand what should be going on well enough to submit a patch - sorry.&lt;/p&gt;


&lt;p&gt;Thanks,&lt;br/&gt;
-Michael&lt;/p&gt;</description>
                <environment>Replica set&lt;br/&gt;
Two mongod instances (one with two votes)</environment>
        <key id="63729">CSHARP-671</key>
            <summary>Driver does not automatically reconnect to secondary</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="9">Done</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="michaelcrino">Michael Crino</reporter>
                        <labels>
                    </labels>
                <created>Wed, 30 Jan 2013 01:59:46 +0000</created>
                <updated>Thu, 20 Mar 2014 14:36:25 +0000</updated>
                            <resolved>Mon, 11 Feb 2013 13:16:01 +0000</resolved>
                                    <version>1.7</version>
                                    <fixVersion>1.8</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="263058" author="auto" created="Mon, 11 Feb 2013 13:14:27 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2013-01-31T21:17:29Z&apos;, u&apos;name&apos;: u&apos;Craig Wilson&apos;, u&apos;email&apos;: u&apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-671&quot; title=&quot;Driver does not automatically reconnect to secondary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-671&quot;&gt;&lt;del&gt;CSHARP-671&lt;/del&gt;&lt;/a&gt;: server sometimes neglects to return setName causing the driver to think that the instance is not a replica set member and we remove it from memory preventing recovery.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/95b83dc73e976b63eb8e338665c34a672e8a5811&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/95b83dc73e976b63eb8e338665c34a672e8a5811&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="256397" author="michaelcrino" created="Sat, 2 Feb 2013 11:23:01 +0000"  >&lt;p&gt;Awesome, thanks for your help!&lt;/p&gt;</comment>
                            <comment id="256377" author="craiggwilson" created="Sat, 2 Feb 2013 10:30:51 +0000"  >&lt;p&gt;Michael, you rock.  Thanks so much.  I&apos;ll test this out and write some tests for the scenario, but it is great to hear that the problem is solved.&lt;/p&gt;

&lt;p&gt;1.8 will be released at the same time server 2.4 is released.  That should be within a month or two.  &lt;/p&gt;

&lt;p&gt;This problem isn&apos;t as bad as it actually sounds.  After the secondary gets removed, it will be gone until another secondary or the primary comes back.  Once that happens, it will get re-added back in.  This is the first time we&apos;ve heard of this so thanks so much for the report.&lt;/p&gt;</comment>
                            <comment id="256322" author="michaelcrino" created="Sat, 2 Feb 2013 07:52:59 +0000"  >&lt;p&gt;A simple test application&lt;/p&gt;</comment>
                            <comment id="256309" author="michaelcrino" created="Sat, 2 Feb 2013 07:22:43 +0000"  >&lt;p&gt;The updated code appears to have resolved this problem! Thank you! Any idea when 1.8 will be released?&lt;/p&gt;


&lt;p&gt;In the interest of documentation I attached  a simple program to reproduce this problem. If you follow the below instructions this occurs every time. I also noticed that if you start the test client before doing anything else the behavior is different... For this test hawk is my secondary; helix my primary.&lt;/p&gt;

&lt;p&gt;&amp;lt;primary&amp;gt;&lt;br/&gt;
echo test123 &amp;gt; mongod.key&lt;br/&gt;
mkdir database&lt;br/&gt;
mongod --keyFile mongod.key --auth --dbpath database --directoryperdb --journal --nohttpinterface -replSet rs0&lt;br/&gt;
mongo&lt;br/&gt;
rs.initiate()&lt;br/&gt;
cnf=rs.conf()&lt;br/&gt;
cnf.members&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;.votes=2&lt;br/&gt;
rs.reconfig(cnf)&lt;br/&gt;
use admin&lt;br/&gt;
db.addUser(&quot;admin&quot;,&quot;test123&quot;)&lt;br/&gt;
db.auth(&quot;admin&quot;,&quot;test123&quot;)&lt;br/&gt;
use test&lt;br/&gt;
db.addUser(&quot;test&quot;,&quot;test123&quot;)&lt;/p&gt;

&lt;p&gt;&amp;lt;secondary&amp;gt;&lt;br/&gt;
echo test123 &amp;gt; mongod.key&lt;br/&gt;
mkdir database&lt;br/&gt;
mongod --keyFile mongod.key --auth --dbpath database --directoryperdb --journal --nohttpinterface -replSet rs0&lt;/p&gt;

&lt;p&gt;&amp;lt;primary&amp;gt;&lt;br/&gt;
rs.add(&quot;hawk&quot;)&lt;/p&gt;

&lt;p&gt;rs.status()&lt;/p&gt;

&lt;p&gt;Launch test app&lt;br/&gt;
Wait 30s or so for everything to come up&lt;/p&gt;

&lt;p&gt;Ctrl-C primary&lt;br/&gt;
Wait 30s or so for everything to switch over&lt;br/&gt;
Ctrl-C secondary&lt;br/&gt;
Wait 30s or so&lt;br/&gt;
Restart secondary&lt;br/&gt;
Wait forever&lt;br/&gt;
Observer the test client doesn&apos;t automatically re-connect&lt;br/&gt;
Restart the test client, observe the test client connecting to the secondary&lt;/p&gt;</comment>
                            <comment id="255073" author="craiggwilson" created="Thu, 31 Jan 2013 21:35:51 +0000"  >&lt;p&gt;Michael,&lt;br/&gt;
  I still haven&apos;t been able to reproduce.  However, I did find one loophole in or server implementation that would cause setName to not get sent back.  Rather, a field called isreplicaset is sent.  I have incorporated that into the checking so as not to incorrectly remove the member.&lt;/p&gt;

&lt;p&gt;  If you wouldn&apos;t mind, I have pushed this to my branch here: &lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp671&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp671&lt;/a&gt;.  If you wouldn&apos;t mind testing this out on your small sample program, that&apos;d be awesome.  This is based on the 1.8 release we are prepping for so some things related to auth have changed.  Let me know if you have any trouble or if you don&apos;t have time to do this.&lt;/p&gt;

&lt;p&gt;Thanks a lot.&lt;/p&gt;</comment>
                            <comment id="254674" author="craiggwilson" created="Thu, 31 Jan 2013 13:28:42 +0000"  >&lt;p&gt;Ok.  Well, at least what is happening matches exactly what I said above.  If the instance type is coming back as StandAlone, it means the server is not sending a replica set name.  This might be a server bug but it&apos;s definitely something that we need to handle.  I&apos;ll try and repro again with your server version and command line options.&lt;/p&gt;</comment>
                            <comment id="254409" author="michaelcrino" created="Thu, 31 Jan 2013 04:28:34 +0000"  >&lt;p&gt;1) I&apos;m using MongoDB v2.2.2&lt;br/&gt;
2) It&apos;s a manual thing. To test the failure I ctrl+C out of the interactively mongod instance to restart it I re-run the command line. The command line I was using is ./mongod --keyFile mongod.key --auth --dbpath database --directoryperdb --journal --nohttpinterface -replSet rs0. The instance type was StandAlone - which I meant to mention originally as that seems odd.&lt;/p&gt;

&lt;p&gt;The replica set was previously initialized.&lt;/p&gt;

&lt;p&gt;The thing I find particularly interesting is if the app/IIS is restarted it works just fine. Additionally I noticed the secondary takes awhile to come online if no primary is available and it can&apos;t elect its self. The secondary is removed from the clients instance lists immediately after the secondary starts up; well before the instance moves into a secondary state.&lt;/p&gt;

&lt;p&gt;I hope that helps. Willing to put together samples or a movie or something if the above is not enough - might take a few days...&lt;/p&gt;

&lt;p&gt;Thanks for your assistance&lt;/p&gt;
</comment>
                            <comment id="254095" author="craiggwilson" created="Wed, 30 Jan 2013 20:34:25 +0000"  >&lt;p&gt;Thanks for reporting Michael...  I started looking into this and unfortunately am having trouble reproducing.  I have a couple of questions that will hopefully lead me in the right direction.&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;What version of the server are you using?&lt;/li&gt;
	&lt;li&gt;When the secondary comes back up, was this automatic or a manual thing?&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The second question here is very important.  The way the driver works is that once it determines you are talking to a replica set, it ensures that all the members it is talking to are in the same replica set.  You pointed to a line of code that seemed to be the culprit.  I would be interested to know what that InstanceType the instance claimed to be?  Was it saying is was a StandAlone, Uknown, or a ShardedRouter.  &lt;/p&gt;

&lt;p&gt;This is important is because the only way it doesn&apos;t end up with an InstanceType == ReplicaSetMember is that when running the isMaster command, it doesn&apos;t report a setName.  This would happen if mongod was started without the replSet option or it was not initialized into a replSet yet.&lt;/p&gt;

&lt;p&gt;Anyways, let me know I&apos;ll continue to work on this. Thanks...&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                                        </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="23744" name="MongoTester.zip" size="3188" author="michaelcrino" created="Sat, 2 Feb 2013 07:52:59 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <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|hrlwgn:</customfieldvalue>

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