<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:46:54 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-3997] ServerMonitor captures execution context for background tasks</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3997</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;When `ServerMonitor` calls `_roundTripTimeMonitor.RunAsync()`, it does not suppress the execution context flow. Because of that, any value present in the execution context when the connection to the server is initialized (= usually when the first instance of `MongoClient` is created) will be captured and kept alive forever by the RoundTripMonitor.&lt;/p&gt;

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

&lt;p&gt;The behavior was observed in 2.13.2, but still present in current version.&lt;/p&gt;

&lt;p&gt;&#160;&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;```&lt;/p&gt;

&lt;p&gt;public class Program&lt;br/&gt;
 {&lt;br/&gt;
&#160; &#160; private static AsyncLocal&amp;lt;object[]&amp;gt; asyncLocal = new();&lt;/p&gt;

&lt;p&gt;&#160; &#160; public static async Task Main(string[] args)&lt;br/&gt;
&#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; Console.WriteLine(TestExecutionContextCapture(InitializeClient));
&#160; &#160; &#160; &#160; Console.WriteLine(TestExecutionContextCapture(Baseline));
&#160; &#160; }

&lt;p&gt;&#160; &#160; private static bool TestExecutionContextCapture(Action action)&lt;br/&gt;
 &#160; &#160; &lt;/p&gt;
{
 &#160; &#160; &#160; &#160; var reference = AllocateAndAssignPayload();

&#160; &#160; &#160; &#160; Task.Run(action).Wait();

&#160; &#160; &#160; &#160; asyncLocal.Value = null;

&#160; &#160; &#160; &#160; GC.Collect(2, GCCollectionMode.Forced, blocking: true);
&#160; &#160; &#160; &#160; GC.WaitForPendingFinalizers();
&#160; &#160; &#160; &#160; GC.Collect(2, GCCollectionMode.Forced, blocking: true);

&#160; &#160; &#160; &#160; return reference.IsAlive;
&#160; &#160; }

&lt;p&gt;&#160; &#160; private static WeakReference AllocateAndAssignPayload()&lt;br/&gt;
&#160; &#160; &lt;/p&gt;
{
&#160; &#160; &#160; &#160; var payload = new object[1024 * 1024];

&#160; &#160; &#160; &#160; asyncLocal.Value = payload;

&#160; &#160; &#160; &#160; return new WeakReference(payload);
&#160; &#160; }

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;```&lt;/p&gt;

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

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

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1948822">CSHARP-3997</key>
            <summary>ServerMonitor captures execution context for background tasks</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="3">Duplicate</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="krix33@gmail.com">Kevin Gosse</reporter>
                        <labels>
                    </labels>
                <created>Tue, 14 Dec 2021 13:36:07 +0000</created>
                <updated>Tue, 14 Dec 2021 14:48:31 +0000</updated>
                            <resolved>Tue, 14 Dec 2021 14:48:31 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4246779" author="dmitry.lukyanov" created="Tue, 14 Dec 2021 14:48:05 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=krix33%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;krix33@gmail.com&quot;&gt;krix33@gmail.com&lt;/a&gt;, thanks for your report.&lt;/p&gt;

&lt;p&gt;We know about this issue and track it in &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3813&quot; title=&quot;Suppress execution context flow when initializing ServerMonitor&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3813&quot;&gt;&lt;del&gt;CSHARP-3813&lt;/del&gt;&lt;/a&gt;, please follow this ticket for updates.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="1859057">CSHARP-3813</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|hzxjg7:</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>