Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2968

Exception occurs when using mongodb+srv connection string

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.10.3
    • Affects Version/s: 2.10.1
    • None
    • Environment:
      AKS (Linux) - Server version v1.14.8

      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.

       

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            jason.jhuboo@asm.org.uk Jason Jhuboo
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: