<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:39:13 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-1303] Socket Connection Error in 2.0 Driver</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1303</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Since going through and updating all of my code to use the mongodb 2.0 driver when I look in my logs I see hundreds of error messages just like the one below where the driver is getting a socket error when connecting to mongo.   When I look at the logs on the mongo server I do not see any error messages.   The site is still up and this error doesn&apos;t happen on every request, nor does it happen on one operation that should take longer.  It is random where it occurs within the application.&lt;/p&gt;

&lt;p&gt;Here is the error:&lt;/p&gt;

&lt;p&gt;MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---&amp;gt; System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 138.91.138.169:27017&lt;br/&gt;
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)&lt;br/&gt;
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.&amp;lt;ConnectAsync&amp;gt;d__7.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.TcpStreamFactory.&amp;lt;CreateStreamAsync&amp;gt;d__0.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.&amp;lt;OpenAsyncHelper&amp;gt;d__1.MoveNext()&lt;br/&gt;
   &amp;#8212; End of inner exception stack trace &amp;#8212;&lt;br/&gt;
   at MongoDB.Driver.Core.Connections.BinaryConnection.&amp;lt;OpenAsyncHelper&amp;gt;d__1.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.Core.Servers.ClusterableServer.&amp;lt;GetChannelAsync&amp;gt;d__0.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()&lt;br/&gt;
   at MongoDB.Driver.Core.Operations.FindOperation`1.&amp;lt;ExecuteAsync&amp;gt;d__2.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.OperationExecutor.&amp;lt;ExecuteReadOperationAsync&amp;gt;d__0`1.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.MongoCollectionImpl`1.&amp;lt;ExecuteReadOperation&amp;gt;d__35`1.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at MongoDB.Driver.IAsyncCursorSourceExtensions.&amp;lt;ToListAsync&amp;gt;d__14`1.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()&lt;br/&gt;
   at CitySpark.EventCache.FlatEventRepo.&amp;lt;GetEventsPagedAsync&amp;gt;d__26.MoveNext()&lt;br/&gt;
&amp;#8212; End of stack trace from previous location where exception was thrown &amp;#8212;&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()&lt;/p&gt;</description>
                <environment>Azure website connecting to a Linux replica set on Azure</environment>
        <key id="209328">CSHARP-1303</key>
            <summary>Socket Connection Error in 2.0 Driver</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="bret@cityspark.com">Bret Ferrier</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Tue, 9 Jun 2015 00:39:56 +0000</created>
                <updated>Mon, 15 Nov 2021 16:52:31 +0000</updated>
                            <resolved>Mon, 4 Apr 2016 15:43:20 +0000</resolved>
                                    <version>2.0</version>
                                                    <component>Connectivity</component>
                    <component>Error Handling</component>
                                        <votes>2</votes>
                                    <watches>19</watches>
                                                                                                                <comments>
                            <comment id="2420708" author="john.murphy" created="Mon, 16 Sep 2019 00:49:50 +0000"  >&lt;p&gt;If you are unable to enable TCP keep alives at the Operating System or Socket level, you can set the &lt;a href=&quot;https://mongodb.github.io/mongo-csharp-driver/2.9/apidocs/html/P_MongoDB_Driver_MongoClientSettings_MaxConnectionIdleTime.htm&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;MaxConnectionIdleTime&lt;/a&gt; to instruct the MongoDB C#/.NET driver to not use pooled connections that may have been severed by the Azure Network Load Balancer.&lt;/p&gt;

&lt;p&gt;This approach however will not proactively detect connections that have been reset unexpectedly, and it will not prevent connections with long running operations from being severed by Azure.&lt;/p&gt;

&lt;p&gt;Therefore we suggest that you utilise the TCP keep alive method when using the MongoDB C#/.NET driver within Azure environments to provide the highest level of connection resilience.&lt;/p&gt;</comment>
                            <comment id="2417483" author="sebainones@gmail.com" created="Thu, 12 Sep 2019 08:06:04 +0000"  >&lt;p&gt;I&apos;m facing the same issue using App Service hosted on Azure connected to a MongoDB&#160;Server outside Azure on a different place.&lt;br/&gt;
I have read what @John Murphy said. My question is (I&apos;m sort of a newbie in this kind of connection issues/scenarios):&lt;br/&gt;
Wouldn&apos;t be enough to set:&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;mongoClientSettings.MaxConnectionIdleTime = TimeSpan.FromMinutes(3);&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;if as he mentioned &quot;environments such as Azure sever idle TCP connections after 4 minutes.&quot; ?&lt;/p&gt;</comment>
                            <comment id="2290857" author="john.murphy" created="Thu, 20 Jun 2019 05:21:10 +0000"  >&lt;p&gt;Note that our &lt;a href=&quot;https://docs.mongodb.com/manual/administration/production-notes/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;production notes&lt;/a&gt; state that environments such as Azure sever idle TCP connections after 4 minutes. Therefore in these environments the keep alive interval needs to be configured to be &lt;tt&gt;120&lt;/tt&gt; seconds.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2543?focusedCommentId=2290849&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-2290849&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;This comment&lt;/a&gt; on &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2543&quot; title=&quot;An exception occurred while receiving a message from the server&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2543&quot;&gt;&lt;del&gt;CSHARP-2543&lt;/del&gt;&lt;/a&gt; shows how to set the interval to 120 seconds.&lt;/p&gt;</comment>
                            <comment id="1660567" author="vrybak@vertmarkets.com" created="Wed, 30 Aug 2017 14:12:40 +0000"  >&lt;p&gt;Even this workaround doesn&apos;t seem to be working for us. &lt;br/&gt;
We use structuremap to make sure that our `IMongoClient`  is a singleton. Here is how we have it setup:&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;For&amp;lt;IMongoClient&amp;gt;().Use(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;&quot;mongoClientCreator&quot;&lt;/span&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;, ctx =&amp;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;	var conn = ctx.GetInstance&amp;lt;IOptions&amp;lt;ConnectionStrings&amp;gt;&amp;gt;().Value.Mongo;&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;&amp;nbsp;&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;	var settings = MongoClientSettings.FromUrl(MongoUrl.Create(conn));&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;	settings.ConnectTimeout = TimeSpan.FromSeconds(&lt;/span&gt;&lt;span style=&quot;color: #009900; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;60&lt;/span&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;	settings.SocketTimeout = TimeSpan.FromMinutes(&lt;/span&gt;&lt;span style=&quot;color: #009900; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;5&lt;/span&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;	settings.MaxConnectionIdleTime = TimeSpan.FromSeconds(&lt;/span&gt;&lt;span style=&quot;color: #009900; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;30&lt;/span&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;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;void&lt;/span&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; SocketConfigurator(Socket s) =&amp;gt; s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;true&lt;/span&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;&amp;nbsp;&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;	settings.ClusterConfigurator = builder =&amp;gt; builder&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;		.ConfigureTcp(tcp =&amp;gt; tcp.With(socketConfigurator: (Action&amp;lt;Socket&amp;gt;)SocketConfigurator));&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;&amp;nbsp;&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;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;return&lt;/span&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;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&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; MongoClient(settings);&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;   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;.Singleton();&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;We also confirmed that our keep alive on the box hosting our code is set correctly &lt;span class=&quot;image-wrap&quot; style=&quot;&quot;&gt;&lt;a id=&quot;164326_thumb&quot; href=&quot;https://jira.mongodb.org/secure/attachment/164326/164326_screenshot-1.png&quot; title=&quot;screenshot-1.png&quot; file-preview-type=&quot;image&quot; file-preview-id=&quot;164326&quot; file-preview-title=&quot;screenshot-1.png&quot;&gt;&lt;img src=&quot;https://jira.mongodb.org/secure/thumbnail/164326/_thumb_164326.png&quot; style=&quot;border: 0px solid black&quot; role=&quot;presentation&quot;/&gt;&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;

&lt;p&gt;We are still getting the same issues that Jeremy was. &lt;br/&gt;
The interesting thing is when we connected to a single mongo machine in Azure this was not an issue. It only when we started connecting to a replica set, that this became a problem for us. &lt;/p&gt;

&lt;p&gt;Are there any other workarounds that we can do?&lt;/p&gt;</comment>
                            <comment id="1659752" author="jeff.yemin" created="Tue, 29 Aug 2017 17:26:47 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=jstafford%40digitalairstrike.com&quot; class=&quot;user-hover&quot; rel=&quot;jstafford@digitalairstrike.com&quot;&gt;jstafford@digitalairstrike.com&lt;/a&gt; thanks for posting your workaround, and also please watch this related ticket to enable TCP Keep-Alive by default: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1994&quot; title=&quot;Enable and configure TCP Keepalive by default&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1994&quot;&gt;&lt;del&gt;CSHARP-1994&lt;/del&gt;&lt;/a&gt;.  &lt;/p&gt;</comment>
                            <comment id="1659647" author="jstafford@digitalairstrike.com" created="Tue, 29 Aug 2017 16:01:19 +0000"  >&lt;p&gt;For what it&apos;s worth, it appears that the driver doesn&apos;t enable socket keep alive by default (strange considering this is a database connection...). The following solved it for us:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Set the duration and interval for socket keep alives in the VM (registry setting)&lt;/li&gt;
	&lt;li&gt;Enable socket keep alive in the C# driver like so:&lt;/li&gt;
&lt;/ul&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;_settings = &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;new&lt;/span&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; MongoClientSettings&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;span style=&quot;color: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// our default settings&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;    ConnectTimeout = TimeSpan.FromSeconds(60),&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;    SocketTimeout = TimeSpan.FromSeconds(60),&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;    MaxConnectionIdleTime = TimeSpan.FromSeconds(60)&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;&amp;nbsp;&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: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// enable keep-alives&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: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;void&lt;/span&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; SocketConfigurator(Socket s) =&amp;gt; s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, &lt;/span&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;true&lt;/span&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;&amp;nbsp;&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;_settings.ClusterConfigurator = builder =&amp;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;   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;    builder.ConfigureTcp(tcp =&amp;gt; tcp.With(socketConfigurator: (Action&amp;lt;Socket&amp;gt;)SocketConfigurator));&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&apos;m surprised the MongoDB team isn&apos;t taking this more seriously. This stuff should be perfect for common use out of the box. To be fair though, apparently MSSQL had the same issue in Azure a while back and solved it in a similar fashion in the ADO driver.&lt;/p&gt;</comment>
                            <comment id="1659337" author="jaume.bresco@tusmedia.com" created="Tue, 29 Aug 2017 09:17:04 +0000"  >&lt;p&gt;We are experiencing the same issue, why is closed?&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                            <comment id="1634868" author="ugenx" created="Fri, 28 Jul 2017 19:03:44 +0000"  >&lt;p&gt;We are still experiencing this issue in Azure and have tried all suggestions thus far to no avail. Why is this closed?&lt;/p&gt;</comment>
                            <comment id="1615658" author="whe@genomichealth.com" created="Thu, 6 Jul 2017 20:48:20 +0000"  >&lt;p&gt;I wonder why this bug is marked as Closed.&lt;br/&gt;
I am getting the same error frequently with new 2.x driver. I have updated to the latest C# driver, v2.4.4. My MongoDB server, 3.4.4, is a small shard with replset of 3, running on Linux hosts in local corporate LAN.&lt;/p&gt;</comment>
                            <comment id="1497197" author="dasjestyr" created="Fri, 10 Feb 2017 23:46:44 +0000"  >&lt;p&gt;So by my reading, Azure&apos;s default timeout is 4 minutes. I set maxIdleTime to 60000 and 10000 and still getting the same problem.&lt;/p&gt;</comment>
                            <comment id="1162881" author="craiggwilson" created="Wed, 3 Feb 2016 21:01:49 +0000"  >&lt;p&gt;Sinan,&lt;/p&gt;

&lt;p&gt;Azure has a low setting for idle connections and kills them when they&apos;ve hit that limit. You need to specify either maxIdleTime on the connection string or MaxConnectionIdleTime in MongoClientSettings to something around 3 minutes. That way, the driver won&apos;t use a connection that has been idle for too long and may have been killed off by azure already.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="1162612" author="deluxetiky" created="Wed, 3 Feb 2016 18:08:27 +0000"  >&lt;p&gt;I have Linux replica set on Azure and my front-end application deployed as a cloud service in Azure. When I send request after a while ( about 10 minutes later after first request )  I always get socket exception error.  &lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond&amp;#93;&lt;/span&gt;&lt;br/&gt;
   System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) +8451915&lt;br/&gt;
   System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) +48&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.&amp;#93;&lt;/span&gt;&lt;br/&gt;
   System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult) +491&lt;br/&gt;
   System.Threading.Tasks.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization) +33&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Misc.&amp;lt;ReadBytesAsync&amp;gt;d__2.MoveNext() +541&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Connections.&amp;lt;ReceiveBufferAsync&amp;gt;d__50.MoveNext() +390&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;MongoConnectionException: An exception occurred while receiving a message from the server.&amp;#93;&lt;/span&gt;&lt;br/&gt;
   MongoDB.Driver.Core.Connections.&amp;lt;ReceiveBufferAsync&amp;gt;d__50.MoveNext() +1079&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Connections.&amp;lt;ReceiveBufferAsync&amp;gt;d__51.MoveNext() +1351&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Connections.&amp;lt;ReceiveMessageAsync&amp;gt;d__53.MoveNext() +765&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.WireProtocol.&amp;lt;ExecuteAsync&amp;gt;d__11.MoveNext() +887&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Servers.&amp;lt;ExecuteProtocolAsync&amp;gt;d__26`1.MoveNext() +542&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Operations.&amp;lt;ExecuteProtocolAsync&amp;gt;d__109.MoveNext() +739&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Operations.&amp;lt;ExecuteAsync&amp;gt;d__107.MoveNext() +1374&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.Core.Operations.&amp;lt;ExecuteAsync&amp;gt;d__107.MoveNext() +1332&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.&amp;lt;ExecuteReadOperationAsync&amp;gt;d__1`1.MoveNext() +377&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MongoDB.Driver.&amp;lt;ExecuteReadOperationAsync&amp;gt;d__59`1.MoveNext() +472&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Repository.IRepository.&amp;lt;GetById&amp;gt;d__31.MoveNext() +423&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Service.Service.&amp;lt;FindClient&amp;gt;d__11.MoveNext() +214&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   MMT.WebApi.AuthProviders.&amp;lt;ValidateClientAuthentication&amp;gt;d__3.MoveNext() +386&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Microsoft.Owin.Security.OAuth.&amp;lt;InvokeTokenEndpointAsync&amp;gt;d__22.MoveNext() +866&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Microsoft.Owin.Security.OAuth.&amp;lt;InvokeAsync&amp;gt;d__0.MoveNext() +1211&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Microsoft.Owin.Security.Infrastructure.&amp;lt;Invoke&amp;gt;d__0.MoveNext() +540&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.&amp;lt;RunApp&amp;gt;d__5.MoveNext() +202&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13877064&lt;br/&gt;
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61&lt;br/&gt;
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.&amp;lt;DoFinalWork&amp;gt;d__2.MoveNext() +193&lt;br/&gt;
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +96&lt;br/&gt;
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +509&lt;br/&gt;
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp;amp; completedSynchronously) +146&lt;/p&gt;</comment>
                            <comment id="1160986" author="suikevil" created="Tue, 2 Feb 2016 15:12:12 +0000"  >&lt;p&gt;Same issue here. &lt;/p&gt;

&lt;p&gt;Error Message:&lt;br/&gt;
A threw exception: MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---&amp;gt; System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---&amp;gt; System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond&lt;/p&gt;

&lt;p&gt;Stack Trace:&lt;br/&gt;
System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)&lt;br/&gt;
System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)&lt;br/&gt;
System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)&lt;br/&gt;
System.IO.Stream.&amp;lt;&amp;gt;c_&lt;em&gt;DisplayClass0.&amp;lt;BeginEndReadAsync&amp;gt;b&lt;/em&gt;_9(Stream stream, IAsyncResult asyncResult)&lt;br/&gt;
System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)&lt;br/&gt;
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
MongoDB.Driver.Core.Misc.StreamExtensionMethods.&amp;lt;ReadBytesAsync&amp;gt;d__0.MoveNext()&lt;br/&gt;
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&lt;br/&gt;
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&lt;br/&gt;
MongoDB.Driver.Core.Connections.BinaryConnection.&amp;lt;ReceiveBufferAsync&amp;gt;d__45.MoveNext()&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;</comment>
                            <comment id="1013028" author="bret@cityspark.com" created="Mon, 24 Aug 2015 16:18:27 +0000"  >&lt;p&gt;Ahmet,  I ended up putting the MaxConnectionIdleTime around 45 seconds and then had to create a set of Extension Methods off of the IFindFluent Interface that included retry logic.  In my testing trying the same query right after the exception was received just about always worked.  Really seems that the retry logic or error handling should be baked in but it is not and doesn&#8217;t seem that anyone is looking at it.&lt;/p&gt;



&lt;p&gt;From: ahmet taha sakar (JIRA)&lt;br/&gt;
Sent: Friday, August 21, 2015 6:39 AM&lt;br/&gt;
To: Bret Ferrier&lt;br/&gt;
Subject: &lt;span class=&quot;error&quot;&gt;&amp;#91;MongoDB-JIRA&amp;#93;&lt;/span&gt; (&lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1303&quot; title=&quot;Socket Connection Error in 2.0 Driver&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1303&quot;&gt;&lt;del&gt;CSHARP-1303&lt;/del&gt;&lt;/a&gt;) Socket Connection Error in 2.0 Driver&lt;/p&gt;



&lt;p&gt;    [ &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;amp;focusedCommentId=1011590#comment-1011590&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org/browse/CSHARP-1303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&amp;amp;focusedCommentId=1011590#comment-1011590&lt;/a&gt; ]&lt;/p&gt;

&lt;p&gt;ahmet taha sakar commented on &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-1303&quot; title=&quot;Socket Connection Error in 2.0 Driver&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-1303&quot;&gt;&lt;del&gt;CSHARP-1303&lt;/del&gt;&lt;/a&gt;:&lt;br/&gt;
------------------------------------------&lt;/p&gt;

&lt;p&gt;I am also having the same issue. I&apos;m on azure. I have default MaxConnectionIdleTime set to 1 minutes from the mongo c# driver.&lt;/p&gt;


&lt;p&gt;----------------------&lt;br/&gt;
This message was sent from MongoDB&apos;s issue tracking system. To respond to this ticket, please login to &lt;a href=&quot;https://jira.mongodb.org&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;https://jira.mongodb.org&lt;/a&gt; using your JIRA or MMS credentials.&lt;/p&gt;

</comment>
                            <comment id="1011590" author="ahmet.sakar@fitwell.com.tr" created="Fri, 21 Aug 2015 12:38:38 +0000"  >&lt;p&gt;I am also having the same issue. I&apos;m on azure. I have default MaxConnectionIdleTime set to 1 minutes from the mongo c# driver.&lt;/p&gt;</comment>
                            <comment id="934761" author="bret@cityspark.com" created="Tue, 9 Jun 2015 02:29:27 +0000"  >&lt;p&gt;Below is the connection string&lt;/p&gt;

&lt;p&gt;    &amp;lt;add name=&quot;mongoEvents&quot; connectionString=&quot;mongodb://remote:7CrazyIdea@xxmongolinux1.cloudapp.net:27017,xxmongolinux2.cloudapp.net:27017/Events?connectTimeoutMS=30000&amp;amp;socketTimeoutMS=30000&amp;amp;waitQueueTimeoutMS=30000&amp;amp;maxIdleTimeMS=45000&quot; /&amp;gt;&lt;/p&gt;

&lt;p&gt;As you can see I am already setting the maxIdleTimeMS,  On another site that we have I found that setting the maxIdleTime to 60000 didn&apos;t actually help but 45000 did solve the idle connection issue on Azure but this seems different.&lt;/p&gt;

&lt;p&gt;-Bret&lt;/p&gt;
</comment>
                            <comment id="934755" author="craiggwilson" created="Tue, 9 Jun 2015 02:17:16 +0000"  >&lt;p&gt;What does your connection string look like? Or your in code setup?&lt;/p&gt;

&lt;p&gt;Azure has something that tends to kill off idle connections. Please try setting the maxIdleTimeMS connection string option to 60000 (1 minute). You can also set this in code using the MaxConnectionIdleTime property on MongoClientSettings. Hopefully, this will clear it up.&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                            <comment id="934738" author="bret@cityspark.com" created="Tue, 9 Jun 2015 01:59:27 +0000"  >&lt;p&gt;Pretty much all of the exceptions I am seeing are the Socket exceptions.&#160; Also this is running as an Azure website.&#160; &lt;/p&gt;

&lt;p&gt;Is there anything I can do with the Mongo driver to handle these exceptions?&lt;/p&gt;


</comment>
                            <comment id="934724" author="craiggwilson" created="Tue, 9 Jun 2015 01:45:33 +0000"  >&lt;p&gt;Hi Bret,&lt;/p&gt;

&lt;p&gt;Sorry you are having issues. This exception is coming straight out of the .NET framework&apos;s Socket class. I assume one your mongod servers is sitting at &lt;tt&gt;138.91.138.169:27017&lt;/tt&gt;. Generally when this exception bubbles to user code, it means that the network is a little flaky. Otherwise, you would also probably be seeing a number of TimeoutExceptions in the logs as well. Is this the only exception you are seeing or are you also seeing TimeoutExceptions? &lt;/p&gt;

&lt;p&gt;Also, are you using Azure or AWS?&lt;/p&gt;

&lt;p&gt;Craig&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="390751">CSHARP-1994</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="164326" name="screenshot-1.png" size="13420" author="vrybak" created="Wed, 30 Aug 2017 14:11:00 +0000"/>
                            <attachment id="87271" name="text.html" size="11634" author="bret@cityspark.com" created="Mon, 24 Aug 2015 16:18:27 +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|hsa4t3:</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>