Accept mongodb+srv connection string without corresponding TXT DNS record

Hi,

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.

Deniz

Hi @Deniz_K,

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.

Regards,
Jeff

2 Likes

Hi Jeff,

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

DNS responses

> dig -t TXT test1.test.build.10gen.cc

; <<>> DiG 9.10.6 <<>> @8.8.8.8 -t TXT test1.test.build.10gen.cc
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: **NOERROR**, id: 59059
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
...
> dig @8.8.8.8 -t TXT srv-test.lens.org

; <<>> DiG 9.10.6 <<>> @8.8.8.8 -t TXT srv-test.lens.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: **NXDOMAIN**, id: 38942
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
...
1 Like

Hi @Deniz_K,

I opened JAVA-4018 (and DRIVERS-1566) to track this. Please follow those issues to keep abreast of any updates or to clarify anything.

In the mean time, are you able to work around the issue?

Regards,
Jeff

2 Likes

Hi @Jeffrey_Yemin,

Thanks for ticketing this issue.

All good at my end, for now I’m creating an empty TXT record as a work around.

Best,
Deniz

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.