SRV connection times out on VPN due to random DNS nameserver order

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: 3.8.0
    • Component/s: None
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      When I'm connected to a VPN (WireGuard) on Windows 11, trying to create a Mongo connection using the "mongodb+srv" protocol is very slow, and sometimes throws a timeout exception after 30 seconds.

      This is because WireGuard sets a DNS server for the VPN interface, and blocks requests to outside DNS servers. This is what I want, and what many VPNs do, and it works fine with other applications (nslookup, browsers, etc.) because they use the OS's DNS resolution, which tries the DNS servers in order of priority, and the VPN DNS server has the highest priority. However, DnsClient.NET, which is used by MongoDB.NET, gets the DNS servers from all my network interfaces, and tries them in random order by default, so depending on my luck, I get from 0 to 4 timeouts before it tries the one working DNS server - or times out.

      Setting LookupClientOptions.UseRandomNameServer = false disables this randomization. I think it would make sense to set that in DnsClientWrapper when creating LookupClient.

      (I've also raised a DnsClient issue about making this the default: https://github.com/MichaCo/DnsClient.NET/issues/250.)

      How to Reproduce

       
      Just run:
       
      MongoClientSettings.FromConnectionString("mongodb+srv://_x-puppet._tcp.dnscheck.co");

      On a VPN that blocks outside DNS servers this is very slow. Without such a VPN it's very fast. (It doesn't matter that there is no Mongo server that address - the DNS lookup of the SRV record is enough to repro.)

      The same thing happens later when actually connecting to the Mongo server, too.

      Additional Background

      CSHARP-2518 seems to be the opposite of this issue.

            Assignee:
            Ferdinando Papale
            Reporter:
            Evgeny Morozov
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: