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’t seem that anyone is looking at it.

 


From: ahmet taha sakar (JIRA)
Sent: Friday, August 21, 2015 6:39 AM
To: Bret Ferrier
Subject: [MongoDB-JIRA] (CSHARP-1303) Socket Connection Error in 2.0 Driver

 

 

 

    [ https://jira.mongodb.org/browse/CSHARP-1303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=1011590#comment-1011590 ]

 

ahmet taha sakar commented on CSHARP-1303:

------------------------------------------

 

I am also having the same issue. I'm on azure. I have default MaxConnectionIdleTime set to 1 minutes from the mongo c# driver.

 

> Socket Connection Error in 2.0 Driver

> -------------------------------------

> 

>                 Key: CSHARP-1303

>                 URL: https://jira.mongodb.org/browse/CSHARP-1303

>             Project: C# Driver

>          Issue Type: Bug

>          Components: Connectivity, Error Handling

>    Affects Versions: 2.0

>         Environment: Azure website connecting to a Linux replica set on Azure

>            Reporter: Bret Ferrier

> 

> 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'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.

> Here is the error:

> MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> 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

>    at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)

>    at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.Core.Connections.TcpStreamFactory.<ConnectAsync>d__7.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.Core.Connections.TcpStreamFactory.<CreateStreamAsync>d__0.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()

>    at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenAsyncHelper>d__1.MoveNext()

>    --- End of inner exception stack trace ---

>    at MongoDB.Driver.Core.Connections.BinaryConnection.<OpenAsyncHelper>d__1.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.Core.Servers.ClusterableServer.<GetChannelAsync>d__0.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()

>    at MongoDB.Driver.Core.Operations.FindOperation`1.<ExecuteAsync>d__2.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.OperationExecutor.<ExecuteReadOperationAsync>d__0`1.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.MongoCollectionImpl`1.<ExecuteReadOperation>d__35`1.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at MongoDB.Driver.IAsyncCursorSourceExtensions.<ToListAsync>d__14`1.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

>    at CitySpark.EventCache.FlatEventRepo.<GetEventsPagedAsync>d__26.MoveNext()

> --- End of stack trace from previous location where exception was thrown ---

>    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

>    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

 

----------------------

This message was sent from MongoDB's issue tracking system. To respond to this ticket, please login to https://jira.mongodb.org using your JIRA or MMS credentials.