<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:09 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-904] C# driver memory leak</title>
                <link>https://jira.mongodb.org/browse/CSHARP-904</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Memory leak in the MongoDB .NET driver.&lt;br/&gt;
My setup is 6 shards/2 servers per RS. Overloaded servers, lot of transport exceptions (might be related to the leak).&lt;br/&gt;
Eventually results in an &quot;Out of memory&quot; exception to be thrown (VERY fast in the real application, with objects up to 16MB).&lt;/p&gt;

&lt;p&gt;I was able to reproduce the issue using the attached test solution (except it occurs much slower than in the real app, because objects are much smaller).&lt;/p&gt;

&lt;p&gt;I&apos;m not sure if the unreliable MongoDB servers are the cause of the memory leak or not.&lt;/p&gt;

&lt;p&gt;I can&apos;t post the Ants Profiler results, because it could contain sensitive information (connection strings, etc.)&lt;/p&gt;</description>
                <environment>Windows Server 2012 R2 x64 / 8.1 x64</environment>
        <key id="109165">CSHARP-904</key>
            <summary>C# driver memory leak</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="-1">Unassigned</assignee>
                                    <reporter username="tubededentifrice">Vincent</reporter>
                        <labels>
                            <label>c#</label>
                            <label>driver</label>
                            <label>leak</label>
                            <label>memory</label>
                            <label>memory-leak</label>
                    </labels>
                <created>Sun, 2 Feb 2014 23:01:54 +0000</created>
                <updated>Tue, 5 Apr 2016 00:28:47 +0000</updated>
                            <resolved>Fri, 20 Jun 2014 14:34:24 +0000</resolved>
                                    <version>1.8.3</version>
                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="629391" author="tubededentifrice" created="Fri, 20 Jun 2014 18:50:55 +0000"  >&lt;p&gt;This problem just reappeared for me since I upgraded to 2.6.2 (and now 2.6.3, same issue). Everything is fine for some days, then I have a very sudden burst in memory consumption to the point I get a OutOfMemoryException (on a 32GB of RAM memory server!).&lt;br/&gt;
I&apos;ll try to gather more data about this.&lt;/p&gt;</comment>
                            <comment id="529431" author="craiggwilson" created="Mon, 31 Mar 2014 15:59:12 +0000"  >&lt;p&gt;Hi Vincent/Peter,&lt;/p&gt;

&lt;p&gt;After much trying and 3 different memory profilers, I simply can&apos;t find any leaks.  I do see a steady rise in the quantity of memory required, but I believe this is related to the test program.  It uses more threads than I have CPU&apos;s, and then attempts to parallelize upserts of 1000 documents.  Ultimately, this will lead to a lot of documents being in memory at any given time.  In addition, in order to serialize classes, we end up with 2x the size of a document in memory (one for the object and one for the serialized form).  I also increased the size of the documents to about 10MB, which makes this much more prounounced.  At some point in the distant future, things basically leveled off for me. I also added finalizers to all the classes that have lots of allocations and were taking a lot of memory, and none of those finalizers ever get called (because the Dispose methods were functioning correctly).&lt;/p&gt;

&lt;p&gt;I&apos;m out of ideas at this point, so I&apos;d love to hear your thoughts.  I&apos;m not saying there isn&apos;t a problem, I&apos;m just not finding it.&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="515109" author="craiggwilson" created="Thu, 13 Mar 2014 12:27:40 +0000"  >&lt;p&gt;I don&apos;t think it was ever assigned to me, I just happened to be triaging it with your help.  &lt;/p&gt;

&lt;p&gt;Update: not much in the way of good news.  This kind of leak is extremely difficult to find and I haven&apos;t yet located it.  Still looking.  I&apos;m trying different things.  For instance, with your sample program, I&apos;ve changed the size of the documents that get inserted/updated to 1MB.  It should make this more pronouncable.  I&apos;m  running it now...&lt;/p&gt;</comment>
                            <comment id="515068" author="peter.aberline@rms.com" created="Thu, 13 Mar 2014 10:09:11 +0000"  >&lt;p&gt;Hi &lt;br/&gt;
I&apos;ve been running it for 24 hours and not seen any exceptions so far.&lt;/p&gt;

&lt;p&gt;Any updates on this Craig? I see this issue is no longer assigned to you and is currently unassigned.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Peter&lt;/p&gt;
</comment>
                            <comment id="513725" author="tubededentifrice" created="Tue, 11 Mar 2014 21:03:04 +0000"  >&lt;p&gt;No, it catches the exceptions thrown on the upsert. In fact I noticed that the leak was happening all the time when my servers were overloaded (and a lot of exceptions were thrown), but I&apos;m not sure it happens again on my system since I upgraded to much more powerful servers. I&apos;m &lt;b&gt;NOT SURE&lt;/b&gt; &amp;#8211; which means it can still happens, but I didn&apos;t check. That&apos;s why I&apos;m asking, maybe it&apos;s a good track to follow.&lt;br/&gt;
However I&apos;m very pleased that another user confirms this issue I&apos;m (was?) experiencing &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&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;try&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;{&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;	collection.Update(Query.EQ(&quot;_id&quot;,obj.Id),Update.Replace(obj),new MongoUpdateOptions {&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;		WriteConcern=WriteConcern.Acknowledged,&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;		Flags=UpdateFlags.Upsert&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;	});&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;}&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;catch(Exception e)&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;{ Console.WriteLine(e.Message); }&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>
                            <comment id="513573" author="peter.aberline@rms.com" created="Tue, 11 Mar 2014 19:14:34 +0000"  >&lt;p&gt;Hi Vincent,&lt;/p&gt;

&lt;p&gt;All I did was run the code you supplied. When it ran out of resources it did throw exceptions yes. But during execution it didn&apos;t appear to throw exceptions as your code stops the work thread in that case. To be sure I&apos;ve added some explicit logging and I&apos;m running it again.&lt;/p&gt;

&lt;p&gt;Thanks&lt;br/&gt;
Peter.&lt;/p&gt;</comment>
                            <comment id="513409" author="tubededentifrice" created="Tue, 11 Mar 2014 16:50:47 +0000"  >&lt;p&gt;Hi Peter,&lt;br/&gt;
Did you experienced mongo exceptions during the leak?&lt;/p&gt;</comment>
                            <comment id="513289" author="peter.aberline@rms.com" created="Tue, 11 Mar 2014 15:08:51 +0000"  >&lt;p&gt;Hi&lt;br/&gt;
Thanks for looking further into this. Since this is now by confirmed by at least 2 different users, with a supporting Ants profile showing a leak, can this case be escalated to a higher priority? I need to eliminate this as the cause of errors we have been seeing.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Peter&lt;/p&gt;</comment>
                            <comment id="513278" author="craiggwilson" created="Tue, 11 Mar 2014 14:55:33 +0000"  >&lt;p&gt;Hi Peter,&lt;/p&gt;

&lt;p&gt;Thanks for this run.  What your profile results seem to show is that our BsonChunkPool is holding on to memory.  This is what it is supposed to be doing as it is a pool of BsonChunks.  I&apos;m going to start investigating if we are leaking chunks that aren&apos;t getting returned.  If that were to happen, I&apos;d expect it to manifest itself a little differently, but you never know.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="512104" author="peter.aberline@rms.com" created="Sun, 9 Mar 2014 12:13:39 +0000"  >&lt;p&gt;Hi,&lt;br/&gt;
It&apos;s now failed while running within Ants Profiler.&lt;br/&gt;
In summary:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;The working set started at around 27Mb.&lt;/li&gt;
	&lt;li&gt;It was reasonably stable for around 24 hours on ~30Mb.&lt;/li&gt;
	&lt;li&gt;After this time is started increasing gradually until 31 hours, plateuing at around 55Mb.&lt;/li&gt;
	&lt;li&gt;Again it was reasonably stable until 62 hours where it started increasing again, and crashed at 63 hours, with a working set of 65Mb.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I&apos;ve attached the Ants Profile results as &quot;memory_leak_test_results.zip&quot;.&lt;/p&gt;</comment>
                            <comment id="511494" author="craiggwilson" created="Fri, 7 Mar 2014 15:16:22 +0000"  >&lt;p&gt;I&apos;ve been running it since yesterday and not seeing much of anything.  It slowly increases for an initial period and then levels, and stays consistent.  I&apos;m watching the Private Bytes and # Bytes in all Heaps performance counters and they aren&apos;t really showing much.  I&apos;ll look forward to your report...  Thanks for helping with this.&lt;/p&gt;</comment>
                            <comment id="511493" author="peter.aberline@rms.com" created="Fri, 7 Mar 2014 15:13:36 +0000"  >&lt;p&gt;I&apos;ve been running this overnight on a test vm using Ant Profiler and I&apos;m getting some interesting results. For the first 12 hours or so the memory usage was stable, but after that it seems to have sprung a small leak and now the memory usage of the test program is slowly increasing. I&apos;ve posted a screenshot as: &quot;ants_results_in_progress.png&quot;&lt;/p&gt;

&lt;p&gt;I&apos;ll leave it running over the weekend and post the Ants results when it finally runs out of resources.&lt;/p&gt;

&lt;p&gt;Thanks&lt;br/&gt;
Peter&lt;/p&gt;</comment>
                            <comment id="510730" author="craiggwilson" created="Thu, 6 Mar 2014 17:05:04 +0000"  >&lt;p&gt;Ok.  I&apos;ll let it run overnight and see what happens.&lt;/p&gt;</comment>
                            <comment id="510728" author="peter.aberline@rms.com" created="Thu, 6 Mar 2014 17:02:55 +0000"  >&lt;p&gt;I reproduced it with a single node running on my dev box. No shards, no replica sets.&lt;br/&gt;
The only change I made to the test program was to the change the connection string to &quot;mongodb://127.0.0.1:27017/TestDev&quot;.&lt;/p&gt;
</comment>
                            <comment id="510721" author="craiggwilson" created="Thu, 6 Mar 2014 16:57:33 +0000"  >&lt;p&gt;I didn&apos;t let it run overnight, so I probably just didn&apos;t let it run long enough...  Can you tell me about your shards?  Is one up, one down, are they all up?  are they all down?  It breaks early if there are none up, and doesn&apos;t break if they are all available.  I also was using a server on my local box, so what exactly is the setup you&apos;re using when running this?&lt;/p&gt;</comment>
                            <comment id="510715" author="peter.aberline@rms.com" created="Thu, 6 Mar 2014 16:54:43 +0000"  >&lt;p&gt;And this was the output of the test program:&lt;/p&gt;


&lt;p&gt;12428 - Started&lt;br/&gt;
12429 - Started&lt;br/&gt;
12430 - Started&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;/p&gt;

&lt;p&gt;Unhandled Exception: Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;/p&gt;

&lt;p&gt;Unhandled Exception: Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
System.AggregateException: One or more errors occurred. ---&amp;gt; MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a conne&lt;br/&gt;
ction.&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnectionPool.AcquireConnection(AcquireConnectionOptions options)&lt;br/&gt;
   at MongoDB.Driver.MongoServerInstance.AcquireConnection()&lt;br/&gt;
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference)&lt;br/&gt;
   at MongoDB.Driver.MongoCursor`1.MongoCursorConnectionProvider.AcquireConnection()&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider)&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.&amp;lt;Execute&amp;gt;d__0.MoveNext()&lt;br/&gt;
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerable.GrabChunk_Buffered(KeyValuePair`2[] des&lt;br/&gt;
tArray, Int32 requestedChunkSize, Int32&amp;amp; actualNumElementsGrabbed)&lt;br/&gt;
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerator.GrabNextChunk(Int32 requestedChunkSize)&lt;/p&gt;

&lt;p&gt;   at System.Collections.Concurrent.Partitioner.DynamicPartitionEnumerator_Abstract`2.MoveNext()&lt;br/&gt;
   at System.Threading.Tasks.Parallel.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass32`2.&amp;lt;PartitionerForEachWorker&amp;gt;b&lt;/em&gt;_30()&lt;br/&gt;
   at System.Threading.Tasks.Task.InnerInvoke()&lt;br/&gt;
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)&lt;br/&gt;
   at System.Threading.Tasks.Task.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass11.&amp;lt;ExecuteSelfReplicating&amp;gt;b&lt;/em&gt;_10(Object param0)&lt;br/&gt;
   &amp;#8212; End of inner exception stack trace &amp;#8212;&lt;br/&gt;
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)&lt;br/&gt;
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)&lt;br/&gt;
   at System.Threading.Tasks.Task.Wait()&lt;br/&gt;
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource,TLocal&amp;#93;&lt;/span&gt;(Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleB&lt;br/&gt;
ody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 local&lt;br/&gt;
Finally)&lt;br/&gt;
   at System.Threading.Tasks.Parallel.ForEachWorker&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource,TLocal&amp;#93;&lt;/span&gt;(IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bod&lt;br/&gt;
yWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)&lt;br/&gt;
   at System.Threading.Tasks.Parallel.ForEach&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source, Action`1 body)&lt;br/&gt;
   at TestMemoryLeak.Program.runTest(String threadName) in c:\Users\paberline\Downloads\TestMemoryLeak\TestMemoryLeak\TestMemoryLeak\Program.cs:line 8&lt;br/&gt;
7&lt;br/&gt;
   at TestMemoryLeak.Program.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass7.&amp;lt;Main&amp;gt;b&lt;/em&gt;_2() in c:\Users\paberline\Downloads\TestMemoryLeak\TestMemoryLeak\TestMemoryLeak\Program.cs:l&lt;br/&gt;
ine 67&lt;br/&gt;
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)&lt;br/&gt;
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx&lt;br/&gt;
)&lt;br/&gt;
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)&lt;br/&gt;
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)&lt;br/&gt;
   at System.Threading.ThreadHelper.ThreadStart()Too many threads are already waiting for a connection.&lt;/p&gt;

&lt;p&gt;System.AggregateException: One or more errors occurred. ---&amp;gt; MongoDB.Driver.MongoConnectionException: Too many threads are already waiting for a conne&lt;br/&gt;
ction.&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnectionPool.AcquireConnection(AcquireConnectionOptions options)&lt;br/&gt;
   at MongoDB.Driver.MongoServerInstance.AcquireConnection()&lt;br/&gt;
   at MongoDB.Driver.MongoServer.AcquireConnection(ReadPreference readPreference)&lt;br/&gt;
   at MongoDB.Driver.MongoCursor`1.MongoCursorConnectionProvider.AcquireConnection()&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider)&lt;br/&gt;
   at MongoDB.Driver.Operations.QueryOperation`1.&amp;lt;Execute&amp;gt;d__0.MoveNext()&lt;br/&gt;
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerable.GrabChunk_Buffered(KeyValuePair`2[] des&lt;br/&gt;
tArray, Int32 requestedChunkSize, Int32&amp;amp; actualNumElementsGrabbed)&lt;br/&gt;
   at System.Collections.Concurrent.Partitioner.DynamicPartitionerForIEnumerable`1.InternalPartitionEnumerator.GrabNextChunk(Int32 requestedChunkSize)&lt;/p&gt;

&lt;p&gt;   at System.Collections.Concurrent.Partitioner.DynamicPartitionEnumerator_Abstract`2.MoveNext()&lt;br/&gt;
   at System.Threading.Tasks.Parallel.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass32`2.&amp;lt;PartitionerForEachWorker&amp;gt;b&lt;/em&gt;_30()&lt;br/&gt;
   at System.Threading.Tasks.Task.InnerInvoke()&lt;br/&gt;
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)&lt;br/&gt;
   at System.Threading.Tasks.Task.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass11.&amp;lt;ExecuteSelfReplicating&amp;gt;b&lt;/em&gt;_10(Object param0)&lt;br/&gt;
   &amp;#8212; End of inner exception stack trace &amp;#8212;&lt;br/&gt;
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)&lt;br/&gt;
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)&lt;br/&gt;
   at System.Threading.Tasks.Task.Wait()&lt;br/&gt;
   at System.Threading.Tasks.Parallel.PartitionerForEachWorker&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource,TLocal&amp;#93;&lt;/span&gt;(Partitioner`1 source, ParallelOptions parallelOptions, Action`1 simpleB&lt;br/&gt;
ody, Action`2 bodyWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 local&lt;br/&gt;
Finally)&lt;br/&gt;
   at System.Threading.Tasks.Parallel.ForEachWorker&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource,TLocal&amp;#93;&lt;/span&gt;(IEnumerable`1 source, ParallelOptions parallelOptions, Action`1 body, Action`2 bod&lt;br/&gt;
yWithState, Action`3 bodyWithStateAndIndex, Func`4 bodyWithStateAndLocal, Func`5 bodyWithEverything, Func`1 localInit, Action`1 localFinally)&lt;br/&gt;
   at System.Threading.Tasks.Parallel.ForEach&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source, Action`1 body)&lt;br/&gt;
   at TestMemoryLeak.Program.runTest(String threadName) in c:\Users\paberline\Downloads\TestMemoryLeak\TestMemoryLeak\TestMemoryLeak\Program.cs:line 8&lt;br/&gt;
7&lt;br/&gt;
   at TestMemoryLeak.Program.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass7.&amp;lt;Main&amp;gt;b&lt;/em&gt;_2() in c:\Users\paberline\Downloads\TestMemoryLeak\TestMemoryLeak\TestMemoryLeak\Program.cs:l&lt;br/&gt;
ine 67&lt;br/&gt;
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)&lt;br/&gt;
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx&lt;br/&gt;
)&lt;br/&gt;
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)&lt;br/&gt;
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)&lt;br/&gt;
   at System.Threading.ThreadHelper.ThreadStart()Too many threads are already waiting for a connection.&lt;/p&gt;

&lt;p&gt;Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
12430 - Upserting new stuff&lt;br/&gt;
12429 - Upserting new stuff&lt;br/&gt;
11568 - 7,011,192 Bytes&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
Too many threads are already waiting for a connection.&lt;br/&gt;
11569 - 6,838,144 Bytes&lt;/p&gt;</comment>
                            <comment id="510711" author="peter.aberline@rms.com" created="Thu, 6 Mar 2014 16:52:37 +0000"  >&lt;p&gt;Hi Craig,&lt;br/&gt;
Thanks for the update. That&apos;s strange you can&apos;t reproduce it. My desktop dev environment is pretty standard. All I did was run the test program overnight. I&apos;m running Mongo 2.4.8 on my desktop machine.&lt;/p&gt;</comment>
                            <comment id="510693" author="craiggwilson" created="Thu, 6 Mar 2014 16:30:58 +0000"  >&lt;p&gt;Hi Peter.  I&apos;m looking into it.  Nothing jumped out as to the cause and the problems don&apos;t seem to occur when the servers are stable and only occasionally when they aren&apos;t (and even then, it seems to self-correct), so I&apos;m really just trying to reproduce still.&lt;/p&gt;</comment>
                            <comment id="510681" author="peter.aberline@rms.com" created="Thu, 6 Mar 2014 16:19:59 +0000"  >&lt;p&gt;Any updates on this? I&apos;ve looked through github commits and not seen any check-ins for this.&lt;br/&gt;
I&apos;ve been able to reproduce this on my local dev machine using the example program connected to a local single node Mongo and I&apos;m currently running it under Ants Memory Profiler. I&apos;ll post the results when it fails.&lt;/p&gt;

&lt;p&gt;We have seen &quot;Timeout waiting for a connection&quot; and &quot;Too many threads are already waiting for a connection&quot; exceptions during our testing. I increased the connectionTimeout, maxPoolSize, waitQueueSize and waitQueueTimeout parameters in the client connection string to address this but it would be good to be able to eliminate this leak as the cause.&lt;/p&gt;

&lt;p&gt;Thanks&lt;br/&gt;
Peter&lt;/p&gt;</comment>
                            <comment id="492182" author="craiggwilson" created="Mon, 3 Feb 2014 14:17:41 +0000"  >&lt;p&gt;Thanks for the report Vincent.  We&apos;ll begin looking into this and try to repro.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="492086" author="tubededentifrice" created="Mon, 3 Feb 2014 02:47:27 +0000"  >&lt;p&gt;Seems really related to exceptions thrown by the drivers, but I don&apos;t know which ones exactly. I think some stuff aren&apos;t correctly disposed when an exception is thrown.&lt;br/&gt;
Exceptions I remember:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;No master found&lt;/li&gt;
	&lt;li&gt;Can&apos;t connect&lt;/li&gt;
	&lt;li&gt;Timeout waiting for a connection&lt;/li&gt;
	&lt;li&gt;Too many threads are already waiting for a connection&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;When the servers are OK, I don&apos;t have the memory leaks.&lt;br/&gt;
This will be pretty hard to reproduce I guess...&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                                                <inwardlinks description="is duplicated by">
                                        <issuelink>
            <issuekey id="150296">CSHARP-1021</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="37085" name="Real app - InstanceCategorizer.png" size="158062" author="tubededentifrice" created="Sun, 2 Feb 2014 23:01:54 +0000"/>
                            <attachment id="37086" name="Real app - Summary.png" size="149228" author="tubededentifrice" created="Sun, 2 Feb 2014 23:01:54 +0000"/>
                            <attachment id="37087" name="Test - InstanceCategorizer.PNG" size="136616" author="tubededentifrice" created="Sun, 2 Feb 2014 23:01:54 +0000"/>
                            <attachment id="37088" name="Test - Summary.PNG" size="171320" author="tubededentifrice" created="Sun, 2 Feb 2014 23:01:54 +0000"/>
                            <attachment id="37089" name="TestMemoryLeak.zip" size="880867" author="tubededentifrice" created="Sun, 2 Feb 2014 23:01:54 +0000"/>
                            <attachment id="39115" name="ants_results_in_progress.png" size="65963" author="peter.aberline@rms.com" created="Fri, 7 Mar 2014 15:13:13 +0000"/>
                            <attachment id="39175" name="memory_leak_test_results.zip" size="12595818" author="peter.aberline@rms.com" created="Sun, 9 Mar 2014 12:18:57 +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|hrvv7j:</customfieldvalue>

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