<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:45:23 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-3477] Potential deadlock in ExclusiveConnectionPool (MaintainSizeAsync)</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3477</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Application info:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;TargetFramework: .NET 5&lt;/li&gt;
	&lt;li&gt;Project type: Microsoft.NET.Sdk.Worker&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;For a few days now, my application sometimes hangs (deadlock?) after an await call to &lt;b&gt;FindAsync&lt;/b&gt; of an &lt;b&gt;IMongoCollection&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;For example:&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;var testCursor = await testCollection.FindAsync(_ =&amp;gt; true);&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;the same also happens for:&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;var testCursor = await testCollection.FindAsync(_ =&amp;gt; true).ConfigureAwait(false);&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;Any line after this call is never reached.&lt;/p&gt;

&lt;p&gt;The problem might happen because I use the API in a wrong way somewhere, but I wasn&apos;t able to recreate a minimal code example to reproduce the issue yet.&lt;/p&gt;

&lt;p&gt;However, the deadlock always happens at this line: &lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/blob/51b48437814cd6d1f4882d1ca2387b1539c8f01f/src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.cs#L227&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/blob/51b48437814cd6d1f4882d1ca2387b1539c8f01f/src/MongoDB.Driver.Core/Core/ConnectionPools/ExclusiveConnectionPool.cs#L227&lt;/a&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;   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;MaintainSizeAsync().ConfigureAwait(false);&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;I don&apos;t know if that line is not using &lt;b&gt;await&lt;/b&gt; on purpose, but I figured it might be an oversight and I post what I found anyway to make sure it is at least checked by a developer who knows more about the code.&lt;/p&gt;

&lt;p&gt;If I manage to create a minimal reproducible example, I will let you know.&lt;/p&gt;</description>
                <environment>TargetFramework: .NET 5&lt;br/&gt;
Project type: Microsoft.NET.Sdk.Worker&lt;br/&gt;
OS: Windows 10&lt;br/&gt;
MongoDB: Community Edition 4.4.3 2008R2Plus SLL (64 bit) - installed as Windows Service</environment>
        <key id="1649319">CSHARP-3477</key>
            <summary>Potential deadlock in ExclusiveConnectionPool (MaintainSizeAsync)</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="13203">Gone away</resolution>
                                        <assignee username="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="inuriasx@gmail.com">Raphael Rabl</reporter>
                        <labels>
                    </labels>
                <created>Mon, 15 Mar 2021 18:55:50 +0000</created>
                <updated>Fri, 27 Oct 2023 19:56:06 +0000</updated>
                            <resolved>Fri, 9 Apr 2021 12:00:00 +0000</resolved>
                                    <version>2.12.0</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="3709787" author="backlog-server-pm" created="Fri, 9 Apr 2021 12:00:00 +0000"  >&lt;p&gt;There hasn&apos;t been any recent activity on this ticket, so we&apos;re resolving it. Thanks for reaching out! Please feel free to comment on this if you&apos;re able to provide more information.&lt;/p&gt;</comment>
                            <comment id="3685130" author="james.kovacs" created="Thu, 25 Mar 2021 23:44:49 +0000"  >&lt;p&gt;Hi, Raphael,&lt;/p&gt;

&lt;p&gt;We have taken a look at the &lt;tt&gt;MaintainSizeAsync&lt;/tt&gt; code more closely. What you observe is expected behaviour. We are starting a background task to periodically prune dead connections and refill the pool to its configured minimum size. We do not await the task because it is never returns until the cancellation token is signalled by the disposal of the connection pool.&lt;/p&gt;

&lt;p&gt;If the code after &lt;tt&gt;FindAsync&lt;/tt&gt; is never called, that indicates that the async task never completes. In order to diagnose this further, we either need a self-contained repro and/or we need to analyze the stack traces and memory in your application when it hangs.&lt;/p&gt;

&lt;p&gt;The self-contained repro is self-explanatory, but it can sometimes be hard to reproduce sporadic events such as this. The second option is collecting a process dump the next time your application hangs and uploading it to us for analysis. The next time your application hangs, please perform the following:&lt;/p&gt;

&lt;p&gt;1. Install dotnet-dump:&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;dotnet tool install --global dotnet-dump&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;2. Collect three or more process dumps over than span of a few minutes:&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;dotnet dump collect -p PID --type Full&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;3. Attach all generated dump files (typically &lt;tt&gt;./core_* }} (Linux) or {{./dump_*.dmp&lt;/tt&gt; (Windows)) to this ticket.&lt;/p&gt;

&lt;p&gt;Step 2 is important as it allows us to compare the states of threads and locks over a span of time. If we only have a single dump file it can be difficult to determine if a thread just happened to be acquiring a lock when the dump was taken or if the thread has been blocked for a significant period of time attempting to acquire that lock.&lt;/p&gt;

&lt;p&gt;Note that the dump files will contain the compressed process memory with any potentially sensitive data such as credentials or user data. If this is a concern, please contact us via this ticket and we will create a secure upload site that you can use to upload the dump files.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any questions.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="3668954" author="mikalai.mazurenka" created="Wed, 17 Mar 2021 14:39:21 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=inuriasx%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;inuriasx@gmail.com&quot;&gt;inuriasx@gmail.com&lt;/a&gt; for your report, we will need some time to investigate it and then we will come back to you.&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_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hykrwn:</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>