<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:40:12 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-1628] Unobserved task exception when connection times out</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1628</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;When server connection times out, an unobserved task exception is thrown, even when synchronous API is used (see stack trace below).&lt;br/&gt;
We have a handler for such exceptions installed globally (from the days when such exceptions terminated current AppDomain), so we occasionally get these traced when servers get down. While they are mostly harmless, I believe these exceptions should be handled and (probably) muted.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.Open(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Servers.ClusterableServer.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.CountOperation.Execute(IReadBinding binding, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.OperationExecutor.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.Count(FilterDefinition`1 filter, CountOptions options, CancellationToken cancellationToken)&lt;/p&gt;&lt;/blockquote&gt;</description>
                <environment></environment>
        <key id="280384">CSHARP-1628</key>
            <summary>Unobserved task exception when connection times out</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="onyxmaster">Aristarkh Zagorodnikov</reporter>
                        <labels>
                    </labels>
                <created>Mon, 18 Apr 2016 08:36:46 +0000</created>
                <updated>Wed, 18 May 2016 20:32:54 +0000</updated>
                            <resolved>Thu, 21 Apr 2016 14:46:25 +0000</resolved>
                                    <version>2.2.2</version>
                                    <fixVersion>2.2.4</fixVersion>
                                    <component>Connectivity</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="1242508" author="onyxmaster" created="Thu, 21 Apr 2016 14:48:19 +0000"  >&lt;p&gt;Ah, sorry, I didn&apos;t pay attention to that part, thanks for the update.&lt;/p&gt;</comment>
                            <comment id="1242504" author="craiggwilson" created="Thu, 21 Apr 2016 14:46:17 +0000"  >&lt;p&gt;It did... because your commit message didn&apos;t include the &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1628&quot; title=&quot;Unobserved task exception when connection times out&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1628&quot;&gt;&lt;del&gt;CSHARP-1628&lt;/del&gt;&lt;/a&gt; text, our JIRA bot didn&apos;t include it here.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commits/master&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commits/master&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1242502" author="onyxmaster" created="Thu, 21 Apr 2016 14:44:26 +0000"  >&lt;p&gt;It appears that the PR didn&apos;t make it into the commit (at least judging from the githook-provided links).&lt;/p&gt;</comment>
                            <comment id="1242486" author="xgen-internal-githook" created="Thu, 21 Apr 2016 14:32:52 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;craiggwilson&apos;, u&apos;name&apos;: u&apos;Craig Wilson&apos;, u&apos;email&apos;: u&apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1628&quot; title=&quot;Unobserved task exception when connection times out&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1628&quot;&gt;&lt;del&gt;CSHARP-1628&lt;/del&gt;&lt;/a&gt;: fixed issue with unobserved task exception.&lt;br/&gt;
Branch: v2.2.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/80e8aba618af54c1dfdbecb4312087d37c2d1cd6&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/80e8aba618af54c1dfdbecb4312087d37c2d1cd6&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1242484" author="xgen-internal-githook" created="Thu, 21 Apr 2016 14:31:59 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;craiggwilson&apos;, u&apos;name&apos;: u&apos;Craig Wilson&apos;, u&apos;email&apos;: u&apos;craiggwilson@gmail.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1628&quot; title=&quot;Unobserved task exception when connection times out&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1628&quot;&gt;&lt;del&gt;CSHARP-1628&lt;/del&gt;&lt;/a&gt;: fixed issue with unobserved task exception.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/7455b09891674c727f9a01717d81ed70045a22eb&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/7455b09891674c727f9a01717d81ed70045a22eb&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1241212" author="craiggwilson" created="Wed, 20 Apr 2016 14:25:14 +0000"  >&lt;p&gt;Yeah, how you described is exactly how I reproduced this. I&apos;ve accepted your PR. I had tried this exact thing but put the call to IgnoreExceptions in a different place and it didn&apos;t help. Moving it to where you put it solved the issue. Putting it through CR now and will get this into 2.2.4.&lt;/p&gt;</comment>
                            <comment id="1240938" author="onyxmaster" created="Wed, 20 Apr 2016 07:59:21 +0000"  >&lt;p&gt;Craig,&lt;/p&gt;

&lt;p&gt;Since the UTE is thrown from the finalizer, the easiest way to repro is to create a separate thread that does GC.Collect() interleaved with Thread.Sleep(1), and then try to perform a database operation in a loop with low connection timeout (see my comment above).&lt;/p&gt;

&lt;p&gt;I tested your fix and it works, but I have a couple of suggestions.&lt;br/&gt;
1. I don&apos;t really think you need to store the exception (it never will be used), calling the accessor is enough&lt;br/&gt;
2. The library already contains Task.IgnoreExceptions extension method that does what I suggest at (1), I think it&apos;s a better way&lt;br/&gt;
3. I believe observing exceptions could be added right after the TCS is set up for additional safety, instead of observing the exception in the handler&lt;/p&gt;

&lt;p&gt;There is a PR for this, see &lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/pull/4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/pull/4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;P.S. I&apos;d name the method ObserveExceptions, since IgnoreExceptions is a bit misleading (should be no problem since it&apos;s internal)&lt;/p&gt;</comment>
                            <comment id="1240214" author="craiggwilson" created="Tue, 19 Apr 2016 16:52:32 +0000"  >&lt;p&gt;Aristarkh,&lt;/p&gt;

&lt;p&gt;I had to do some code manipulation to get this to repro. The issue is that we create a TaskCompletionSource even on the sync path as our BinaryConnection class is thread-safe and used from both the sync and async stack. So, basically assigning the exception to a dummy variable seems to have fixed the issue. If you are able, would you mind building from source and trying this out in your scenario? It is located on my fork here: &lt;a href=&quot;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp1628&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/craiggwilson/mongo-csharp-driver/tree/csharp1628&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Craig&lt;/p&gt;</comment>
                            <comment id="1240011" author="onyxmaster" created="Tue, 19 Apr 2016 14:35:22 +0000"  >&lt;p&gt;Connecting to replica set with connection timeout (MongoClientSettings.ConnectTimeout) set to absurdly low value (like 1 ms for a machine over WAN) worked for us.&lt;br/&gt;
Don&apos;t forget to install unobserved handler, or there will be nothing to catch =)&lt;/p&gt;</comment>
                            <comment id="1239993" author="craiggwilson" created="Tue, 19 Apr 2016 14:27:39 +0000"  >&lt;p&gt;Hi Aristarkh,&lt;/p&gt;

&lt;p&gt;I have a theory but am having trouble reproducing it. I&apos;ll let you know what I find. If you know of a way to reliably reproduce this, let me know.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="1238332" author="onyxmaster" created="Mon, 18 Apr 2016 08:40:53 +0000"  >&lt;p&gt;A bit more detailed stack trace:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;   at MongoDB.Driver.Core.Connections.TcpStreamFactory.Connect(Socket socket, EndPoint endPoint, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStream(EndPoint endPoint, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)&lt;br/&gt;
   &amp;#8212; End of inner exception stack trace &amp;#8212;&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.Open(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Servers.ClusterableServer.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindOperation`1.Execute(IReadBinding binding, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.OperationExecutor.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperation&lt;span class=&quot;error&quot;&gt;&amp;#91;TResult&amp;#93;&lt;/span&gt;(IReadOperation`1 operation, CancellationToken cancellationToken)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.FindSync&lt;span class=&quot;error&quot;&gt;&amp;#91;TProjection&amp;#93;&lt;/span&gt;(FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)&lt;/p&gt;&lt;/blockquote&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <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|hskilb:</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>