Intermittent "Authentication failed because the remote party has closed the transport stream." - Mongo C#

asked by on

Since switching to Mongo SSL connection, using the C# Driver (v1.11.0), we have been getting intermittent errors in production with this error message:

Authentication failed because the remote party has closed the transport stream.

Our connection string is in this format:

mongodb://user:[email protected]:port1,host2:port2,host3:port3/dbname?ssl=true&authsource=admin&sslVerifyCertificate=true&replicaSet=replicaSetName

The DB is hosted in MongoDB ATLAS offering, not sure if that will make any difference.

The stack trace prior to our own classes is:

at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at MongoDB.Driver.Internal.MongoConnection.Open()
at MongoDB.Driver.Internal.MongoConnection.SendMessage(BsonBuffer buffer, Int32 requestId)
at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage message)
at MongoDB.Driver.Operations.QueryOperation`1.GetFirstBatch(IConnectionProvider connectionProvider)
at MongoDB.Driver.Operations.QueryOperation`1.Execute(IConnectionProvider connectionProvider)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)

We have upgraded to .NET 4.61 and placed the following line in our global asax application start:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

At a loss at what else to look at, and its hard to troubleshoot as we're unable to debug locally... any help much appreciated!

0 Answers