<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:47:38 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-4236] connecting to mongo instance 300+ times result with error: System.outofmemory exception</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4236</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;I have a C# program, basically, it connects to all mongo instances, and get the version information. to ensure that the mongodb version is as expected. The program works smoothly for driver version 2.14.1 for long time. Recently, I upgrade Mongo C# driver version from 2.14.1 to 2.15.0 and above, and program throw error below:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;processing: &#160; &#160;328 of 452&lt;/em&gt;&lt;br/&gt;
&lt;em&gt;error: System.OutOfMemoryException:&#160; type is &#8220;System.OutOfMemoryException&#8221;&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark&amp;amp; stackMark)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at System.Threading.Thread.Start(StackCrawlMark&amp;amp; stackMark)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at System.Threading.Thread.Start()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.Core.Servers.RoundTripTimeMonitor.Start()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.Core.Servers.ServerMonitor.Initialize()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.Core.Servers.DefaultServer.InitializeSubClass()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.Core.Servers.Server.Initialize()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.Core.Clusters.MultiServerCluster.Initialize()&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.ClusterRegistry.CreateCluster(ClusterKey clusterKey)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(ClusterKey clusterKey)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at MongoDB.Driver.MongoClient..ctor(MongoUrl url)&lt;/em&gt;&lt;br/&gt;
&#160; &#160;&lt;em&gt;at Ctrip.DBConfig.Business.MongoCheckVersion.check()&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Pleaseprovidetheversionofthedriver.Ifapplicable%2CpleaseprovidetheMongoDBserverversionandtopology%28standalone%2Creplicaset%2Corshardedcluster%29.&quot;&gt;&lt;/a&gt;Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).&lt;/h4&gt;

&lt;p&gt;2.15.0,&#160; 2.15.1, 2.16.0 and 2.16.1&#160; work smoothly for 2.14.1 and below.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; List&amp;lt;MongoClusterInfo&amp;gt; MongoClusterList = SQLMonitorV3.getMongoClusterList();&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; for (int i = 0; i &amp;lt; MongoClusterList.Count; i++)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string cluster_name = MongoClusterList&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.cluster_name;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string env_type = MongoClusterList&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.env_type;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string cluster_type = MongoClusterList&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.cluster_type;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; int status = MongoClusterList&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.status;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; int is_dr = MongoClusterList&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.is_dr;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string user = &quot;username&quot;;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string pwd = &quot;password&quot;;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string connString = &quot;mongodb://&quot; + user + &quot;:&quot; + pwd + &quot;@&quot;;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Console.WriteLine(&quot;processing:&quot; + &quot;\t&quot; + i.ToString() + &quot; of &quot; + MongoClusterList.Count.ToString());&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (cluster_type.Equals(&quot;sharding&quot;))&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; List&amp;lt;MongoInstanceInfo&amp;gt; MongoInstanceList = SQLMonitorV3.getMongoInstanceList(cluster_name + &quot;mongos&quot;);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; for (int j = 0; j &amp;lt; MongoInstanceList.Count; j++)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string mongos_ip = MongoInstanceList[j].ip_business;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string mongos_port = MongoInstanceList[j].port;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString += mongos_ip + &quot;:&quot; + mongos_port + &quot;,&quot;;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString = connString.Substring(0, connString.Length - 1);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString += &quot;/?authSource=admin&quot;;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; List&amp;lt;MongoInstanceInfo&amp;gt; MongoInstanceList = SQLMonitorV3.getMongoInstanceList(cluster_name);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; for (int j = 0; j &amp;lt; MongoInstanceList.Count; j++)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string machine_name = MongoInstanceList[j].machine_name;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string ip_business = MongoInstanceList[j].ip_business;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string port = MongoInstanceList[j].port;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string role = MongoInstanceList[j].role;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string mongodb_version = MongoInstanceList[j].mongodb_version;

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (role.ToLower().Equals(&quot;arbiter&quot;)) continue;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (role.ToLower().Equals(&quot;mongos&quot;)) continue;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString += ip_business + &quot;:&quot; + port + &quot;,&quot;;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString = connString.Substring(0, connString.Length - 1);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; connString += &quot;/admin&quot; + &quot;?replicaSet=&quot; + cluster_name;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; try&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; var mongourl = new MongoUrl(connString);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MongoClient client = new MongoClient(mongourl);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; var db = client.GetDatabase(&quot;admin&quot;);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; BsonDocument result = db.RunCommand&amp;lt;BsonDocument&amp;gt;(new BsonDocument(&quot;buildInfo&quot;, 1));&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string version = (string)result.GetValue(&quot;version&quot;);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; string allocator = (string)result.GetValue(&quot;allocator&quot;);&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (!(version.Equals(&quot;4.0.19&quot;) &#160;||&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; version.Equals(&quot;4.2.17&quot;) ||&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; version.Equals(&quot;4.2.19&quot;) ||&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; version.StartsWith(&quot;4.2.&quot;) ||&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; version.Equals(&quot;4.2.18&quot;)))&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{

&#160;Console.WriteLine(&quot;expected&quot;);

&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; continue;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (!allocator.Equals(&quot;tcmalloc&quot;))&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{

&#160;Console.WriteLine(&quot;expected&quot;);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&#160;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; catch (Exception e)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Console.WriteLine(&quot;error: &quot;&#160; + e.ToString());
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&lt;p&gt;&#160; &#160; &#160; &#160; &#160; &#160; }//end of for&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Steps to reproduce. If possible, please include a &lt;a href=&quot;http://sscce.org/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;Short, Self Contained, Correct (Compilable), Example&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;em&gt;ensure we have more than 400 mongo instances to check.&lt;/em&gt;&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Run the above program, it will throw out error when in around iteration 330.&lt;/em&gt;&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Only the iteration number counts. I skip some iterations, and it will hit error later&lt;/em&gt;&lt;/li&gt;
	&lt;li&gt;&lt;em&gt;Note, once I revert driver back to 2.14.1. it works fine.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;&#160;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;AdditionalBackground&quot;&gt;&lt;/a&gt;Additional Background&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Please provide any additional background information that may be helpful in diagnosing the bug.&lt;/em&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2078514">CSHARP-4236</key>
            <summary>connecting to mongo instance 300+ times result with error: System.outofmemory exception</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="13202">Works as Designed</resolution>
                                        <assignee username="dmitry.lukyanov@mongodb.com">Dmitry Lukyanov</assignee>
                                    <reporter username="rgyu@trip.com">rgyu N/A</reporter>
                        <labels>
                    </labels>
                <created>Tue, 28 Jun 2022 14:03:56 +0000</created>
                <updated>Fri, 27 Oct 2023 13:24:40 +0000</updated>
                            <resolved>Wed, 29 Jun 2022 19:00:14 +0000</resolved>
                                    <version>2.15.0</version>
                    <version>2.15.1</version>
                    <version>2.16.0</version>
                    <version>2.16.1</version>
                                                    <component>Connectivity</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4647485" author="JIRAUSER1270001" created="Wed, 29 Jun 2022 12:54:04 +0000"  >&lt;p&gt;thanks. I changed to use ClusterRegistry.Instance.UnregisterAndDisposeCluster(client.Cluster);, and observe the memory usage with Visual Studio diagnostic sessions.&#160; Now the memory usage is flat. Previsouly, it is sharp increasing. thanks again, and the problem is resolved.&#160;&lt;/p&gt;
&lt;h2&gt;&lt;a name=&quot;&quot;&gt;&lt;/a&gt;&lt;/h2&gt;</comment>
                            <comment id="4647190" author="dmitry.lukyanov" created="Wed, 29 Jun 2022 10:11:20 +0000"  >&lt;p&gt;I&apos;m not sure what you mean by posted code above. That code is related to the legacy driver. You didn&apos;t use it initially.&lt;br/&gt;
&#160;&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;MongoClient client = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; MongoClient(mongourl);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;processing code...&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;client.Cluster.Dispose(); &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;this is not enough. You also should unregister disposed cluster. You should use:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;ClusterRegistry.UnregisterAndDisposeCluster(mongoClient.Cluster);  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;blockquote&gt;&lt;p&gt;Better if we can have an explict Open/Close like other database client drivers though. &#160;Thank you very much for your suggestions.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;we&apos;re planning to make our client disposable, but this will be a significant breaking change, so it will be done only in next major driver release, see this &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3431&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;ticket&lt;/a&gt; for updates&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="4647121" author="JIRAUSER1270001" created="Wed, 29 Jun 2022 09:16:58 +0000"  >&lt;p&gt;thank you very much for your response,&#160; It seems the application reaches the server limit. Somehow I run the application, and hit the limitation below. the default _maxServerCount is 100.&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; internal static MongoServer Create(MongoServerSettings settings, IOperationExecutor operationExecutor)&lt;br/&gt;
&#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; lock (__staticLock)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MongoServer server;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (!__servers.TryGetValue(settings, out server))&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; {&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (__servers.Count &amp;gt;= __maxServerCount)&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; var message = string.Format(&quot;MongoServer.Create has already created \{0}
&lt;p&gt; servers which is the maximum number of servers allowed.&quot;, __maxServerCount);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; throw new MongoException(message);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; server = new MongoServer(settings, operationExecutor);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; __servers.Add(settings, server);&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; return server;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; }&lt;br/&gt;
&#160; &#160; &#160; &#160; }&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;I changed the program, and add the below code after each usage, the the patrol program runs fine again.&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;var mongourl = new MongoUrl(connString);&lt;br/&gt;
MongoClient client = new MongoClient(mongourl);&lt;/p&gt;

&lt;p&gt;processing code...&lt;/p&gt;

&lt;p&gt;client.Cluster.Dispose();&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Better if we can have an explict Open/Close like other database client drivers though.&#160; Thank you very much for your suggestions.&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="4644902" author="dmitry.lukyanov" created="Tue, 28 Jun 2022 14:48:54 +0000"  >&lt;p&gt;Hey &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=rgyu%40trip.com&quot; class=&quot;user-hover&quot; rel=&quot;rgyu@trip.com&quot;&gt;rgyu@trip.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;I cannot reproduce this issue on my windows x64 machine. Here some notes that might bring some light on your issue.&lt;br/&gt;
1. The difference between 2.14.1 and 2.15 versions is that now we create (2 * Number of server endpoints) internal background thread instances for each mongo client where previously we used TPL tasks for this target. It was done in this way to handle some issues with suppressing execution context we had with the previous implementation. &lt;br/&gt;
Assuming that all your connection strings are different, effectively it means even for simple standalone server with single endpoint, in your 328 attempts you created 328 * 2 = 656 threads that ping server in addition to buildInfo requests you&apos;re doing in your application which somehow causes out of memory exception on your machine. If your server is replica set with 3 nodes, then a number of internal background threads for each mongo client will be 2 * 3 = 6.&lt;br/&gt;
2. If your application uses x32-bit, switching to x64 should help with it. &lt;br/&gt;
3. Although we do not usually recommend it, you may try using the below approach to release memory after each particular client that also should resolve your issue: &lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;ClusterRegistry.UnregisterAndDisposeCluster(mongoClient.Cluster);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&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_21553" key="com.atlassian.jira.plugin.system.customfieldtypes:labels">
                        <customfieldname>Quarter</customfieldname>
                        <customfieldvalues>
                                        <label>FY22Q3</label>
    
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i0j56o:</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>