[CSHARP-1195] Driver is not re-establishing connection to MongoDb Created: 18/Mar/15  Updated: 02/Apr/16  Resolved: 19/Mar/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0

Type: Bug Priority: Blocker - P1
Reporter: Sergey Ivasenko Assignee: Unassigned
Resolution: Done Votes: 0
Labels: rc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:
  • Windows 7 Ent., .NET FW-4.5.2, ASP.NET Web.Api application
  • MongoDb: v-3.0.x, single server setup


 Description   

Operation execution is not restored after the service restart. Seems like this is only the issue for ASP.NET apps, hence console app is able to restore connection/operation execution when the service as back online again.



 Comments   
Comment by Sergey Ivasenko [ 19/Mar/15 ]

Hi Craig,

Your commit fixed the issue, connection is restored now.

Thanks a lot!
Sergey

Comment by Sergey Ivasenko [ 19/Mar/15 ]

Yes, we'll do that and come back with the results.

Thanks a lot,
Sergey

Comment by Craig Wilson [ 19/Mar/15 ]

Sergey, thanks so much for the report. I was able to reproduce this problem. After many false leads, we found some missing ConfigureAwaits in the code. After adding these, I can't reproduce this problem anymore. If you wouldn't mind pulling master and ensuring the problem is gone, that'd be most helpful.

Thanks again.
Craig

Comment by Sergey Ivasenko [ 19/Mar/15 ]

Thanks a lot, Craig!

Comment by Craig Wilson [ 19/Mar/15 ]

Commit: https://github.com/mongodb/mongo-csharp-driver/commit/1c6fa135c46cf35887809a7021636d93174ab770

Comment by Sergey Ivasenko [ 18/Mar/15 ]

Hi Craig,

Thanks for quick reply!

1. Driver 2.0.0-rc0 (2.0.0.788)
2. Test case:

  • MongoDb service is running
  • Request data from collection => result returned
  • Stop MongoDb service
  • Request data from collection => Web.Api app logs 3 exception:
    1. System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it... <TRUNCATED>
    2. ERROR System.Runtime.Serialization.SerializationException: Type 'MongoDB.Driver.MongoConnectionException' with data contract name 'MongoConnectionException:http://schemas.datacontract.org/2004/07/MongoDB.Driver' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.
    at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
    at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiTypeAtTopLevel(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle originalDeclaredTypeHandle, Type graphType)
    at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, DataContractResolver dataContractResolver)
    at System.Runtime.Serialization.DataContractSerializer.WriteObject(XmlWriter writer, Object graph)
    at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)
    at System.Net.Http.Formatting.XmlMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
      • 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.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext() GET Url:http://xxxxxxxxx
        3. Same as (2)
  • Start MongoDb service
  • Request data from collection => Exception: ERROR System.TimeoutException: Operation timed out after 00:00:10. ---> System.OperationCanceledException: The operation was canceled.
    at System.Threading.CancellationToken.ThrowOperationCanceledException()
    at MongoDB.Driver.Core.Clusters.Cluster.<WaitForDescriptionChangedAsync>d__1a.MoveNext()
      • End of stack trace from previous location where exception was thrown —
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        at MongoDB.Driver.Core.Clusters.Cluster.<SelectServerAsync>d__8.MoveNext()
      • End of stack trace from previous location where exception was thrown —
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        at MongoDB.Driver.Core.Bindings.ReadPreferenceBinding.<GetReadChannelSourceAsync>d__0.MoveNext()
      • End of stack trace from previous location where exception was thrown —
        at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        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.ExceptionServices.ExceptionDispatchInfo.Throw()
        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() <TRUNCATED>

If the web is recycled (iisreset), then app can query data again.
No caching done in app.

Comment by Craig Wilson [ 18/Mar/15 ]

Hi Sergey, thanks for the report. Could you provide some more details:

1. What version of the driver are you using?
2. Could you elaborate on the problem? When you say service restart, do you mean restarting the system, or IIS, or...? Perhaps you could provide a reproducible scenario and I'll attempt to reproduce it. Also, what are you expecting to happen.

Thanks,
Craig

Generated at Wed Feb 07 21:38:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.