[CSHARP-2968] Exception occurs when using mongodb+srv connection string Created: 14/Feb/20  Updated: 28/Oct/23  Resolved: 06/Apr/20

Status: Closed
Project: C# Driver
Component/s: Connectivity, Error Handling
Affects Version/s: 2.10.1
Fix Version/s: 2.10.3

Type: Bug Priority: Major - P3
Reporter: Jason Jhuboo Assignee: Dmitry Lukyanov (Inactive)
Resolution: Fixed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

AKS (Linux) - Server version v1.14.8


Attachments: Text File clusterm10-shard-00-00-u06qs.mongodb.net_2020-02-13T00_00_00_2020-02-14T00_00_00_mongodb.log    
Issue Links:
Duplicate
is duplicated by CSHARP-2852 DnsClient.DnsResponseException: Unhan... Closed
Related
related to CSHARP-2977 Unable to connect to name server Closed
related to CSHARP-2518 Dns resolver only uses first DNS server. Closed
Case:

 Description   

Our C# applications have been quite happily connecting to various MongoDB Atlas clusters using the SRV connection string for roughly a year now. Since the start of this month, (and about 2 weeks after we upgraded to .NET Core 3.1), we started getting an error with the MongoDB connection 'Record reader index out of sync.'
 
Looking into it a bit further, it appears that the problem manifests in in the DnsClient package (v1.2.0). It seems to work just fine on my windows machine, on my linux boxes, but not within my AKS environment.
Suspiciously, Microsoft have recently started rolling out a change to CoreDNS ( https://github.com/Azure/AKS/blob/master/CHANGELOG.md )
 
Spoke to Mary Gorman at support and tested this out on an M10 instance, same results and have the logs attached (though I suspect the problem is within AKS and nothing to do with the database itself).
 
This can be recreated using .NET Core 3.1 and a reference to the DnsClient package and the following code running in a .NET Core 3.1 Alpine container within AKS:
 
````
class Program
{
static void Main(string[] args)
{
try

{ LookupClient client = new LookupClient(); IDnsQueryResponse result = client.Query("_mongodb._tcp.clusterm10-u06qs.mongodb.net", QueryType.SRV); Console.WriteLine($"Error: \{result.HasError}

");

foreach (DnsResourceRecord dnsResourceRecord in result.AllRecords)
Console.WriteLine(dnsResourceRecord.ToString());
}
catch (Exception e)

{ Console.WriteLine(e); }

Console.ReadLine();
}
}

````

Replace the mongoDB host for a valid cluster if the one supplied is no longer there - this happens on the free tier and M10 lookups.

You will end up with an error that looks like this:

````

DnsClient.DnsResponseException: Unhandled exception
---> System.InvalidOperationException: Record reader index out of sync.
at DnsClient.DnsRecordFactory.GetRecord(ResourceRecordInfo info) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\DnsRecordFactory.cs:line 181
at DnsClient.DnsMessageHandler.GetResponseMessage(ArraySegment`1 responseData) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\DnsMessageHandler.cs:line 114
at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\DnsUdpMessageHandler.cs:line 66
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsQuerySettings settings, DnsMessageHandler handler, DnsRequestMessage request, LookupClientAudit continueAudit) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\LookupClient.cs:line 724
— End of inner exception stack trace —
at DnsClient.LookupClient.ResolveQuery(IReadOnlyCollection`1 servers, DnsQuerySettings settings, DnsMessageHandler handler, DnsRequestMessage request, LookupClientAudit continueAudit) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\LookupClient.cs:line 835
at DnsClient.LookupClient.QueryInternal(DnsQuestion question, DnsQuerySettings settings, IReadOnlyCollection`1 useServers) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\LookupClient.cs:line 650
at DnsClient.LookupClient.Query(String query, QueryType queryType, QueryClass queryClass, DnsQueryOptions queryOptions) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Src\LookupClient.cs:line 401
at DnsClientTest.Program.Main(String[] args) in C:\Users\jason\Source\Repos\DnsClientTest\DnsClientTest\Program.cs:line 15

````

 

Please note, that this error only occurs within AKS! It does not seem to manifest on a Windows 10 machine, or on a Linux box outside of AKS.

 

This has been cross reported here: https://github.com/MichaCo/DnsClient.NET/issues/51

 

I can obviously get round this issue by not using seedless connection strings (non SRV connection strings), but SRV connection strings are far preferable from a maintainability point of view.

 



 Comments   
Comment by Githook User [ 03/Apr/20 ]

Author:

{'name': 'DmitryLukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-2968: Exception occurs when using seedless connection string in AKS.
Branch: v2.10.x
https://github.com/mongodb/mongo-csharp-driver/commit/067940db605ff769297407bbad48f9ace10bc441

Comment by Githook User [ 03/Apr/20 ]

Author:

{'name': 'DmitryLukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}

Message: CSHARP-2968: Exception occurs when using seedless connection string in AKS.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/dc3849cf52f190c0e48479a3cbba32ed78d18f4c

Comment by Dmitry Lukyanov (Inactive) [ 02/Apr/20 ]

Hello fernanda.palomino, it will be fixed in the next patch release.

Comment by Jason Jhuboo [ 02/Apr/20 ]

@Fermanda Palmino - I think that you don't need to wait for a new driver release - your customers can just reference the latest DnsClient package (>=1.3.0)  which will supersede the version referenced by the MongoDB C# NuGET package. This package contains the fix, and the MongoDB NuGet package just requires >=1.2.0 if the DnsClient package, soooo it should just work

 

I think v1.3.1 of the package is out now.

Comment by Fernanda Palomino [ 02/Apr/20 ]

Hi dmitry.lukyanov a couple of customers are having issues when using SRV conn string from their apps on .net C#. Do we know in which version this bug will be fixed so we can update those customers? Thanks!

Comment by Michael Conrad [ 12/Mar/20 ]

There are also a couple of duplicate issues here. At least I'm pretty sure its the same bug in DnsClient 1.2.0 which will be resolved in 1.3.0:

 

Comment by Michael Conrad [ 11/Mar/20 ]

Hi (author of DnsClient here),

I'm not sure if that's the best way of communicating this but yes, version 1.2.0 has a bug which causes issues right not in AKS which apparently started sending more information then the library expected.

This bug seems to be fixed in version 1.3.0. I'm currently in the process of finalizing the release by testing it more and verifying that the bug is fixed.

 

Sorry for any inconveniences,

Thanks,
M

Comment by Jason Jhuboo [ 09/Mar/20 ]

Please see https://github.com/MichaCo/DnsClient.NET/issues/51 - it looks like the problem has been identified and a fix is going to be added to v1.3.0 of the DncClient.NET package

Comment by Ranil Mohothadura [ 02/Mar/20 ]

Look like this is not only happening on AKS , but in plain Docker instance created based on .net core 3.1  image gives the same error

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