<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:41:29 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-2055] Sudden burst of &quot;Exception = &apos;MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a connection.&quot;</title>
                <link>https://jira.mongodb.org/browse/CSHARP-2055</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Our ecosystem uses MongoDB as preferred storage engine (we are running 3.2 Enterprise version server) and c# driver 1.11. From last two days our system is throwing exceptions to establish connection&lt;br/&gt;
And it says &quot;MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a connection.&quot;&lt;/p&gt;

&lt;p&gt;We are using all default settings for establishing the connection.&lt;/p&gt;

&lt;p&gt;After googling for a while, people suggested to increase the &quot;MaxConnectionPoolSize&quot; &amp;amp; &quot;WaitQueueSize&quot; settings, what are the ideal settings?&lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Manju&lt;/p&gt;

&lt;p&gt;[Exception = &apos;MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a connection.&lt;br/&gt;
Server stack trace: &lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnectionPool.AcquireConnection(AcquireConnectionOptions options) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\MongoConnectionPool.cs:line 97&lt;br/&gt;
   at MongoDB.Driver.MongoServerInstance.AcquireConnection() in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\MongoServerInstance.cs:line 465&lt;br/&gt;
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\MongoServer.cs:line 964&lt;br/&gt;
   at MongoDB.Driver.MongoCursor`1.MongoCursorConnectionProvider.AcquireConnection() in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\MongoCursor.cs:line 1049&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 112&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 77&lt;br/&gt;
   at System.Linq.Enumerable.FirstOrDefault&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source)&lt;/p&gt;</description>
                <environment></environment>
        <key id="441323">CSHARP-2055</key>
            <summary>Sudden burst of &quot;Exception = &apos;MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a connection.&quot;</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="13202">Works as Designed</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="manjunath.bhuyar@hp.com">Manjunath Bhuyar</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Thu, 5 Oct 2017 19:42:13 +0000</created>
                <updated>Fri, 27 Oct 2023 13:25:06 +0000</updated>
                            <resolved>Fri, 13 Oct 2017 18:05:28 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1691116" author="manjunath.bhuyar@hp.com" created="Fri, 6 Oct 2017 04:26:31 +0000"  >&lt;p&gt;Hi Robert,&lt;/p&gt;

&lt;p&gt;Found the issue, it was bad indexing on our part, our couple of collections were running on peak with multiple queries running very very slow. That made the server super slow to respond. Connection rates were running in 2.7K range, after applying proper index everything came back to normal and now connections are under 250&lt;/p&gt;

&lt;p&gt;Thank you for the support and we can close the case.&lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Manju&lt;/p&gt;</comment>
                            <comment id="1691063" author="manjunath.bhuyar@hp.com" created="Fri, 6 Oct 2017 01:37:51 +0000"  >&lt;p&gt;Attached is the cluster monitoring graphs, which show a sudden spike in activity in the last two days &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;a id=&quot;167450_thumb&quot; href=&quot;https://jira.mongodb.org/secure/attachment/167450/167450_cluster+health.PNG&quot; title=&quot;cluster health.PNG&quot; file-preview-type=&quot;image&quot; file-preview-id=&quot;167450&quot; file-preview-title=&quot;cluster health.PNG&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/thumbnail/167450/_thumb_167450.png&quot; style=&quot;border: 0px solid black&quot; role=&quot;presentation&quot;/&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;</comment>
                            <comment id="1691046" author="manjunath.bhuyar@hp.com" created="Fri, 6 Oct 2017 00:22:25 +0000"  >&lt;p&gt;Hi Robert,&lt;/p&gt;

&lt;p&gt;No luck with the setting of Poolsize to 300, still seeing connection failures. And the connection issues are happening on only one Database on the cluster and other DB&apos;s are having a different error&lt;br/&gt;
our ops person is checking the cluster for any issues in parallel &lt;/p&gt;

&lt;p&gt;-Manju &lt;/p&gt;

&lt;p&gt;Connection issue Stack trace&lt;br/&gt;
********************************************************&lt;br/&gt;
Server stack trace: &lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnectionPool.AcquireConnection(AcquireConnectionOptions options) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\MongoConnectionPool.cs:line 161&lt;br/&gt;
   at MongoDB.Driver.MongoServerInstance.AcquireConnection() in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\MongoServerInstance.cs:line 465&lt;br/&gt;
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\MongoServer.cs:line 964&lt;br/&gt;
   at MongoDB.Driver.MongoCursor`1.MongoCursorConnectionProvider.AcquireConnection() in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\MongoCursor.cs:line 1049&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 112&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 77&lt;br/&gt;
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)&lt;br/&gt;
   at System.Linq.Enumerable.ToList&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source)&lt;br/&gt;
   at HP.Sds.DeviceDataProcessor.Dal.DbGroup.ConsumableMongoDbGroup.GetActiveConsumablesForDevice(Int64 jamCustomerId, Int64 jamDeviceId) in C:\Agent&amp;#95;work\12\s\DeviceDataProcessor\src\Dal\DbGroup\ConsumableMongoDbGroup.cs:line 54&lt;/p&gt;


&lt;p&gt;ReadPreference issue stack trace&lt;br/&gt;
*************************************************************&lt;br/&gt;
Exception = QueryFailure flag was could not find host matching read preference { mode: &quot;primary&quot;, tags: [ {} ] } for set shard1 (response was { &quot;$err&quot; : &quot;could not find host matching read preference { mode: \&quot;primary\&quot;, tags: [ {} ] } for set shard1&quot;, &quot;code&quot; : 133 })., Stack Trace = &lt;br/&gt;
Server stack trace: &lt;br/&gt;
   at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadHeaderFrom(BsonBuffer buffer) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\Messages\MongoReplyMessage.cs:line 123&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(BsonBinaryReaderSettings readerSettings, IBsonSerializer serializer, IBsonSerializationOptions serializationOptions) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Communication\MongoConnection.cs:line 295&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 119&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider) in d:\jenkins\workspace\mongo-csharp-driver-1.x-build\MongoDB.Driver\Operations\QueryOperation.cs:line 77&lt;br/&gt;
   at System.Linq.Enumerable.FirstOrDefault&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source)&lt;br/&gt;
   at HP.Sds.ActionService.Dal.DbGroup.DeviceMongoDbGroup.AddDevice(Device entity) in C:\Agent&amp;#95;work\27\s\ActionService\src\Dal\DbGroup\DeviceMongoDbGroup.cs:line 26&lt;/p&gt;</comment>
                            <comment id="1690760" author="manjunath.bhuyar@hp.com" created="Thu, 5 Oct 2017 20:17:29 +0000"  >&lt;p&gt;Thank you Robert, we will try your suggestion and double the values. &lt;/p&gt;

&lt;p&gt;Regards&lt;br/&gt;
Manju &lt;/p&gt;</comment>
                            <comment id="1690751" author="rstam" created="Thu, 5 Oct 2017 20:12:52 +0000"  >&lt;p&gt;There is no single setting that is ideal for everyone.&lt;/p&gt;

&lt;p&gt;You want MaxConnectionPoolSize to be big enough to handle spikes in load without:&lt;/p&gt;

&lt;p&gt;1. Allowing too many connections to be opened (overloading the server with connections)&lt;br/&gt;
2. Having to wait too long for a connection to be released&lt;/p&gt;

&lt;p&gt;You want WaitQueueSize to be big enough to handle spikes in load without:&lt;/p&gt;

&lt;p&gt;1. Throwing an exception because the wait queue is full&lt;/p&gt;

&lt;p&gt;So the ideal setting will depend on your load.&lt;/p&gt;

&lt;p&gt;Given that you are seeing these exceptions we can deduce that your load has grown to the point where your current settings are no longer adequate.&lt;/p&gt;

&lt;p&gt;Perhaps the easiest thing is to double each of the values and see whether that prevents further exceptions.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="167450" name="cluster health.PNG" size="89896" author="manjunath.bhuyar@hp.com" created="Fri, 6 Oct 2017 01:37:45 +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|ht92fr:</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>