Currently, the Java driver expects a TXT DNS record when using a seed list mongodb+srv://... connection string.
From the documentation it seems that the TXT record is optional and the mongo shell client implementation doesn’t expect it either.
I was wondering if the Java driver can be adjusted so that TXT DNS record becomes optional.
I had a look at this and I think you are mistaken in your analysis of the Java driver code. If there is no TXT record, a NamingException is not thrown, so that catch block is not entered. Rather, the Attribute for “TXT” will be null, the conditional here will be skipped, and the method will just return the empty string.
To confirm this, you can run the test com.mongodb.client.InitialDnsSeedlistDiscoveryTest, which implements this test suite, which contains several hosts with no TXT records.
Let me know if you have additional questions, or if you’re seeing something different in actual testing.
Thanks for looking into this.
It seems a NameNotFoundException is thrown if the DnsClient receives a status 3 (NXDOMAIN) for a non-existent domain, which I believe is a valid scenario.
To reproduce, you should be able to use the tests below with two connection strings.
The first one succeeds, with a NOERROR response for the TXT DNS query. I assume there is another non-TXT record for this name, or special DNS configuration.
The second test fails, due to a NXDOMAIN response (AWS Route53 resolver). There is no DNS entry at all for that domain name.
Deniz
Tests
@Test
public void testNOERROR() {
ConnectionString connectionString = new ConnectionString("mongodb+srv://test1.test.build.10gen.cc/");
assertEquals(connectionString.getConnectionString(), "mongodb+srv://test1.test.build.10gen.cc/");
}
@Test
public void testNXDOMAIN() {
// _mongodb._tcp.srv-test.lens.org SRV record exists
// srv-test.lens.org record does not exist
new ConnectionString("mongodb+srv://srv-test.lens.org/");
}
Stack trace
com.mongodb.MongoConfigurationException: Unable to look up TXT record for host srv-test.lens.org
at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:131)
at com.mongodb.ConnectionString.<init>(ConnectionString.java:378)
at MongoDbSrvTest.testNXDOMAIN(MongoDbSrvTest.java:34)
...
Caused by: javax.naming.NameNotFoundException: DNS name not found [response code 3]; remaining name 'srv-test.lens.org'
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.checkResponseCode(DnsClient.java:661)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.isMatchResponse(DnsClient.java:579)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:427)
at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:212)
at jdk.naming.dns/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
at jdk.naming.dns/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
at java.naming/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
at java.naming/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
at java.naming/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:142)
at com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:114)
... 67 more