<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:57 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-153] Wrapping internal communication exceptions</title>
                <link>https://jira.mongodb.org/browse/CSHARP-153</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;I would like to suggest wrapping internal I/O exceptions in a custom exception (i.e. MongoCommunicationException).&lt;br/&gt;
Imagine the following scenario: &lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;I connect to a replica set and begin perform queries&lt;/li&gt;
	&lt;li&gt;Suddenly, the server I was querying goes down and the NetworkStream.Read() throws IOException, which gets to my code&lt;/li&gt;
	&lt;li&gt;I have no knowledge which exceptions could be thrown from the below code and if I should retry the operation (catching all types of exceptions, especially in a hosted environment is very risky, think ThreadAbortException for example).&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;But, if the connection management layer of the driver would wrap all I/O-related exceptions into one type of exceptions (a new one, MongoCommunicationException or even the existing one MongoConnectionException), the driver user would instantly know that there was a problem with MongoDB connection, not some fluke in his code, and retrying/reporting failure becomes much easier.&lt;/p&gt;</description>
                <environment></environment>
        <key id="14262">CSHARP-153</key>
            <summary>Wrapping internal communication exceptions</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="3">Duplicate</resolution>
                                        <assignee username="craig.wilson@mongodb.com">Craig Wilson</assignee>
                                    <reporter username="onyxmaster">Aristarkh Zagorodnikov</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 Jan 2011 09:36:26 +0000</created>
                <updated>Wed, 14 May 2014 19:04:18 +0000</updated>
                            <resolved>Thu, 24 May 2012 21:05:42 +0000</resolved>
                                    <version>1.0</version>
                                    <fixVersion>2.0</fixVersion>
                                    <component>Feature Request</component>
                                        <votes>2</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="161860" author="craiggwilson" created="Sat, 8 Sep 2012 00:27:26 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-474&quot; title=&quot;Review all exceptions thrown by the C# driver&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-474&quot;&gt;&lt;del&gt;CSHARP-474&lt;/del&gt;&lt;/a&gt; will handle this.&lt;/p&gt;</comment>
                            <comment id="122906" author="craiggwilson" created="Thu, 24 May 2012 21:05:42 +0000"  >&lt;p&gt;We will be reviewing all exceptions as part of the 2.0 release as making changes like this are backwards breaking.&lt;/p&gt;</comment>
                            <comment id="105753" author="rstam" created="Mon, 2 Apr 2012 17:04:11 +0000"  >&lt;p&gt;The coding is relatively trivial. The difficult part is analyzing all the places an exception might be thrown and deciding &lt;b&gt;if&lt;/b&gt; to wrap the exceptions, &lt;b&gt;which&lt;/b&gt; exceptions to wrap, and &lt;b&gt;what&lt;/b&gt; to wrap them with.&lt;/p&gt;</comment>
                            <comment id="105635" author="edussooriya" created="Mon, 2 Apr 2012 11:24:06 +0000"  >&lt;p&gt;is there a way to help you guys by coding on this project ?&lt;/p&gt;</comment>
                            <comment id="98992" author="rstam" created="Thu, 15 Mar 2012 02:25:17 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-152&quot; title=&quot;MongoConnectionStringBuilder fails at constructor using a connection string&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-152&quot;&gt;&lt;del&gt;CSHARP-152&lt;/del&gt;&lt;/a&gt;, &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-155&quot; title=&quot;Support for error codes in command results and exceptions&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-155&quot;&gt;&lt;del&gt;CSHARP-155&lt;/del&gt;&lt;/a&gt; and &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-393&quot; title=&quot;MongoConnectionPool should throw some kind of MongoException (MongoConnectionException?) instead of TimeoutException&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-393&quot;&gt;&lt;del&gt;CSHARP-393&lt;/del&gt;&lt;/a&gt; are all related in that they all are about how errors are presented to the caller (what exception type, what error message, are there any codes or additional data available to facilitate programmatic interpretation of the exception, etc...). These are being pushed to at least 1.5 to allow time for discussions to occur with other driver writers with the goal of presenting a mostly unified solution.&lt;/p&gt;</comment>
                            <comment id="39174" author="onyxmaster" created="Fri, 24 Jun 2011 22:05:33 +0000"  >&lt;p&gt;In our environment (I can&apos;t speak for everyone of course), the only exceptions we occur when the primary goes away is IOException that originates in the already wrapped code (hence the 2-line patch, we never saw any other exceptions that needed wrapping). While I believe there are other places that might need additional attention, I think they might be addressed in one of a future patches, that will further reduce the number of distinct exceptions that might be thrown from the inner workings of the driver. On the other hand, &quot;driver experience&quot; can be improved right now by getting the wrapper in MongoConnection.HandleException and/or wrapping other places that are mentioned in Miguel&apos;s patch.&lt;br/&gt;
P.S. I don&apos;t think the MongoAuthenticationException and other non-transient exceptions should be wrapped since they already have a defined meaning that is readily known to the client, so I think making a catch-all block, blindly converting any exception to a MongoConnectionException won&apos;t do any good, since if there&apos;s an error in the driver code (for example there&apos;s an ArgumentException or an NullReferenceException thrown in some rare cases when parsing server response), it should not be handled like MongoConnectionException (this would do more harm than good), thus the proposed IOException as the main candidate for conversion.&lt;/p&gt;</comment>
                            <comment id="39094" author="mpilar" created="Fri, 24 Jun 2011 16:39:10 +0000"  >&lt;p&gt;I think that is not what the immediate concern is, at least for me the main issue are the exceptions that are already being caught, processed and then rethrown. I think those main sticking points can be addressed quickly.&lt;/p&gt;</comment>
                            <comment id="39068" author="rstam" created="Fri, 24 Jun 2011 14:20:53 +0000"  >&lt;p&gt;It&apos;s OK to pester... &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;I didn&apos;t have time to get this into 1.1.&lt;/p&gt;

&lt;p&gt;The difficulty is that it&apos;s not just one place that should be wrapped. I probably need to examine the whole code base to find all the places where lower level exceptions should be wrapped, and that&apos;s a big job.&lt;/p&gt;</comment>
                            <comment id="39041" author="onyxmaster" created="Fri, 24 Jun 2011 08:35:45 +0000"  >&lt;p&gt;Sorry for pestering, any planned progress on this?&lt;/p&gt;</comment>
                            <comment id="30511" author="onyxmaster" created="Sat, 30 Apr 2011 18:19:43 +0000"  >&lt;p&gt;I would like to propose an even simple exception handling mechanism that would have very low impact and would fit into existing connection exception handling pattern &amp;#8211; just extend HandleException error checks.&lt;/p&gt;</comment>
                            <comment id="28848" author="mpilar" created="Tue, 12 Apr 2011 20:11:43 +0000"  >&lt;p&gt;Quick patch wrapping communication exceptions that are being re-thrown with MongoConnectionException and a generic message.&lt;/p&gt;</comment>
                            <comment id="27394" author="onyxmaster" created="Thu, 31 Mar 2011 08:01:27 +0000"  >&lt;p&gt;Example exception:&lt;/p&gt;

&lt;p&gt;System.IO.IOException: Unable to read data from the transport connection. ---&amp;gt; System.Net.Sockets.SocketException: &lt;br/&gt;
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)&lt;br/&gt;
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)&lt;br/&gt;
   &amp;#8212; End of inner exception stack trace &amp;#8212;&lt;br/&gt;
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)&lt;br/&gt;
   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\IO\BsonBuffer.cs:line 272&lt;br/&gt;
   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\IO\BsonBuffer.cs:line 248&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(MongoServer server) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 338&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.GetReply(MongoRequestMessage message) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoCursorEnumerator.cs:line 202&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.GetMore() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoCursorEnumerator.cs:line 194&lt;br/&gt;
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoCursorEnumerator.cs:line 103&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="14291">CSHARP-155</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="30783">CSHARP-393</issuekey>
        </issuelink>
                            </outwardlinks>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="39411">CSHARP-474</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="11677" name="CS-153.patch" size="5430" author="mpilar" created="Tue, 12 Apr 2011 20:11:43 +0000"/>
                            <attachment id="11791" name="MongoConnection.cs.patch" size="420" author="onyxmaster" created="Sat, 30 Apr 2011 18:19:43 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10011"><![CDATA[Minor Change]]></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|hrh4i7:</customfieldvalue>

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