<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:39:13 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-1302] MongoClient Connection issues.</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1302</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I have an issue with connections failing in a certain scenario:&lt;/p&gt;

&lt;p&gt;Architecture:&lt;/p&gt;

&lt;p&gt;website#1 with primary#1&lt;br/&gt;
website#2 with secondary#2&lt;br/&gt;
website#3 with secondary#3&lt;/p&gt;

&lt;p&gt;Settings: new MongoClientSettings&lt;/p&gt;
                       {
                           ReplicaSetName = &quot;rs&quot;,
                           Servers = &amp;lt; 3 server names &amp;gt;,
                           ConnectionMode = ConnectionMode.ReplicaSet,
                           ConnectTimeout = new TimeSpan(0,0,60),
                           ReadPreference = (slaveOk) ? ReadPreference.Nearest : ReadPreference.Primary,
                           WriteConcern = WriteConcern.Acknowledged, 
                       }

&lt;p&gt;&amp;#8211;&lt;br/&gt;
I run this command:&lt;br/&gt;
var client = MongoClient(Settings);&lt;br/&gt;
await client.GetDatabase(&quot;admin&quot;).RunCommandAsync(&quot;&lt;/p&gt;
{replSetGetStatus:1}
&lt;p&gt;&quot;)&lt;/p&gt;

&lt;p&gt;and generally receive a correct response with myState either being 1 or 2.&lt;/p&gt;

&lt;p&gt;&amp;#8211;&lt;/p&gt;

&lt;p&gt;However, sometimes whilst these sites are running I will take offline secondary#2 - and run up a local non-rs instance on port 37017. When I do that, website#2 begins to respond with:&lt;/p&gt;

&lt;p&gt;A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector&lt;/p&gt;
{ AllowedLatencyRange = 00:00:00.0150000 }
&lt;p&gt; }. Client view of cluster state is { ClusterId : &quot;1&quot;, Type : &quot;ReplicaSet&quot;, State : &quot;Disconnected&quot;, Servers : [{ ServerId: &quot;&lt;/p&gt;
{ ClusterId : 1, EndPoint : &quot;Unspecified/127.0.0.1:27017&quot; }
&lt;p&gt;&quot;, ....&lt;/p&gt;

&lt;p&gt;Now - I would have expected the website to fall over to retrieve secondary#3 - but its not doing that.&lt;/p&gt;

&lt;p&gt;Am I doing something wrong?&lt;br/&gt;
Should perhaps my MongoClient be more globalized within the AppDomain (maybe - but is it related).&lt;/p&gt;

&lt;p&gt;Hope you can help.&lt;/p&gt;
</description>
                <environment></environment>
        <key id="209166">CSHARP-1302</key>
            <summary>MongoClient Connection issues.</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="-1">Unassigned</assignee>
                                    <reporter username="paul.reed">Paul Reed</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Mon, 8 Jun 2015 16:59:21 +0000</created>
                <updated>Fri, 5 Apr 2019 13:58:45 +0000</updated>
                            <resolved>Mon, 8 Jun 2015 18:18:10 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="934233" author="craiggwilson" created="Mon, 8 Jun 2015 18:18:10 +0000"  >&lt;p&gt;In most cases, it won&apos;t matter because if the settings are the same, we&apos;ll use the same cluster underneath. However, this isn&apos;t always true because there are certain types of settings we cannot compare.&lt;/p&gt;

&lt;p&gt;To be safe, it is always best practice to use a single MongoClient for your application. Stick it in your IoC container or something.&lt;/p&gt;

&lt;p&gt;Since we&apos;ve figured this out, I&apos;m going to go ahead and close this ticket.&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="934224" author="paul.reed" created="Mon, 8 Jun 2015 18:13:04 +0000"  >&lt;p&gt;Oh Golly,&lt;/p&gt;

&lt;p&gt;Thank you:&lt;/p&gt;

&lt;p&gt;#if !DEBUG&lt;br/&gt;
            useLocal = true;&lt;br/&gt;
#endif&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;            if (useLocal)&lt;/p&gt;
            {
                servers.Add(new MongoServerAddress(&quot;127.0.0.1&quot;, port));
            }

&lt;p&gt;Cannot believe that this has been added in at some stage - it used to be #if DEBUG.. -  and of course the port is coming in at the correct value. So amazingly every thing works out normally.&lt;/p&gt;

&lt;p&gt;&amp;#8211;&lt;/p&gt;

&lt;p&gt;#redface&lt;/p&gt;

&lt;p&gt;===&lt;/p&gt;

&lt;p&gt;So, just one last thing. When using MongoClient/MongoServer within a WebSite ( utilising ApplicationPooling ) - should we be using a single MongoClient/Server per app pool instance ?&lt;br/&gt;
Or does it actually not matter if we generate many new MongoClient(settings) calls.&lt;/p&gt;
</comment>
                            <comment id="934211" author="craiggwilson" created="Mon, 8 Jun 2015 18:04:29 +0000"  >&lt;p&gt;Right. Are you giving it 127.0.0.1 anywhere in your code? For some reason, we aren&apos;t connecting to a replica set here, just the local mongod. I&apos;ve attempted to replicate this and am not having any luck. Somehow, the 3 servers you are indicating in your MongoClientSettings are not getting used. Is there anyway you could provide a reproduction of this with actual code so that I can debug through it?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="934185" author="paul.reed" created="Mon, 8 Jun 2015 17:57:02 +0000"  >&lt;p&gt;If it is trying to connect to the Primary, then I really am not sure why it is using:  127.0.0.1:27017 as this is the local address to the secondary. Non of the server addresses are in IP format.&lt;br/&gt;
The server addresses are presented within the settings in the order &lt;a href=&quot;#1,Secondary#2, Secondary#3&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;Primary#1,Secondary#2, Secondary#3&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="934179" author="paul.reed" created="Mon, 8 Jun 2015 17:53:08 +0000"  >&lt;p&gt;re: 1) &lt;br/&gt;
we have websites and mongod running across 3 servers. The websites are not heavy load - all the load is within mongod.&lt;/p&gt;

&lt;p&gt;re:  2) &lt;/p&gt;

&lt;p&gt;A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector&lt;/p&gt;
{ AllowedLatencyRange = 00:00:00.0150000 }
&lt;p&gt; }. Client view of cluster state is { ClusterId : &quot;1&quot;, Type : &quot;ReplicaSet&quot;, State : &quot;Disconnected&quot;, Servers : [{ ServerId: &quot;&lt;/p&gt;
{ ClusterId : 1, EndPoint : &quot;Unspecified/127.0.0.1:27017&quot; }
&lt;p&gt;&quot;, EndPoint: &quot;Unspecified/127.0.0.1:27017&quot;, State: &quot;Disconnected&quot;, Type: &quot;Unknown&quot;, HeartbeatException: &quot;MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---&amp;gt; System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:27017 &lt;br/&gt;
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) &lt;br/&gt;
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Connections.TcpStreamFactory.d__7.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Connections.TcpStreamFactory.d__0.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() &lt;br/&gt;
at MongoDB.Driver.Core.Connections.BinaryConnection.d__1.MoveNext() &lt;br/&gt;
&amp;#8212; End of inner exception stack trace &amp;#8212; &lt;br/&gt;
at MongoDB.Driver.Core.Connections.BinaryConnection.d__1.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Servers.ClusterableServer.d__d.MoveNext()&quot; }] }.&lt;br/&gt;
at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description) &lt;br/&gt;
at MongoDB.Driver.Core.Clusters.Cluster.d__18.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Clusters.Cluster.d__6.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Bindings.WritableServerBinding.d__0.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.Core.Operations.WriteCommandOperation`1.d__0.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.OperationExecutor.d__3`1.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at MongoDB.Driver.MongoDatabaseImpl.d__7`1.MoveNext() &lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212; &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) &lt;br/&gt;
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) &lt;br/&gt;
at #########.MongoDataConnection.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass20.&amp;lt;b&lt;/em&gt;&lt;em&gt;1b&amp;gt;d&lt;/em&gt;_22.MoveNext()&lt;br/&gt;
===&lt;/p&gt;

&lt;p&gt;re: 3)&lt;/p&gt;

&lt;p&gt;The primary is up at all times, &lt;br/&gt;
website#2 is still up, but has no secondary running on it - just a local instance running non-rs. &lt;br/&gt;
secondary#2 was cleanly brought down off of 27017 - and then a local instance ran up on 37017.&lt;br/&gt;
website#1 and website#3 also run this command and respond with no issue&apos;s.&lt;br/&gt;
All the function is doing is to try and ascertain if I have a functional replicaset - I have had problems in the past with the sites being ready before mongo has had time to come up into a ready state. When this happens I correctly get the timeout which holds up my site processing correctly. I&lt;/p&gt;</comment>
                            <comment id="934161" author="craiggwilson" created="Mon, 8 Jun 2015 17:32:13 +0000"  >&lt;p&gt;Hi Paul,&lt;/p&gt;

&lt;p&gt;Sorry you are having issues. Couple of questions:&lt;/p&gt;

&lt;p&gt;1. I don&apos;t completely understand what you&apos;ve said about your architecture. Are you running your mongod instances on the same servers as your website servers?&lt;br/&gt;
2. In the exception message you&apos;ve provided, you didn&apos;t include the entire message. Could you provide the entire message. It let&apos;s us know exactly what the state of the cluster is when the timeout failed. &lt;br/&gt;
3. In the exception message you&apos;ve provided, it is attempting to find a Primary. The fact that it didn&apos;t means that no primary was available. (WritableServerSelector = find a primary). When you run a command, it will always use a read preference of primary regardless of your settings. There is an optional parameter on RunCommandAsync which allows you to provide a read preference: &lt;a href=&quot;http://api.mongodb.org/csharp/2.0/html/M_MongoDB_Driver_IMongoDatabase_RunCommandAsync__1.htm&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://api.mongodb.org/csharp/2.0/html/M_MongoDB_Driver_IMongoDatabase_RunCommandAsync__1.htm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;
</comment>
                            <comment id="934143" author="paul.reed" created="Mon, 8 Jun 2015 17:18:53 +0000"  >&lt;p&gt;FYI&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;useSlave == true&lt;br/&gt;
so the ReadPreference is Nearest&lt;/li&gt;
&lt;/ul&gt;
</comment>
                    </comments>
                    <attachments>
                    </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|hsa43j:</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>