Unable to look up TXT record for mongo host from Azure Windows App Service

I am using Azure to deploy my service, which would talk to MongoDB.

Previously, I am using Azure Linux App Service, and everything could work well.
However, I am trying to deploy my service onto Azure Windows App Service, but it would have DNS issue. Error log is as following:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.client.MongoClient]: Factory method 'mongoClient' threw exception; nested exception is com.mongodb.MongoConfigurationException: Unable to look up TXT record for host cluster0.xe4in.mongodb.netat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)... 218 moreCaused by: com.mongodb.MongoConfigurationException: Unable to look up TXT record for host cluster0.xe4in.mongodb.netat com.mongodb.internal.dns.DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords(DefaultDnsResolver.java:131)at com.mongodb.ConnectionString.<init>(ConnectionString.java:384)at com.leland.config.MongoConfig.buildMongoClientSettings(MongoConfig.java:49)at com.leland.config.MongoConfig.mongoClient(MongoConfig.java:45)at com.leland.config.MongoConfig$$EnhancerBySpringCGLIB$$df102bd2.CGLIB$mongoClient$14(<generated>)at com.leland.config.MongoConfig$$EnhancerBySpringCGLIB$$df102bd2$$FastClassBySpringCGLIB$$11b79bd1.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)at com.leland.config.MongoConfig$$EnhancerBySpringCGLIB$$df102bd2.mongoClient(<generated>)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.base/java.lang.reflect.Method.invoke(Method.java:566)at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)... 219 moreCaused by: javax.naming.CommunicationException: DNS error [Root exception is java.net.SocketTimeoutException: Receive timed out]; remaining name 'cluster0.xe4in.mongodb.net'at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:313)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)... 232 moreCaused by: java.net.SocketTimeoutException: Receive timed outat java.base/java.net.TwoStacksPlainDatagramSocketImpl.receive0(Native Method)at java.base/java.net.TwoStacksPlainDatagramSocketImpl.receive(TwoStacksPlainDatagramSocketImpl.java:123)at java.base/java.net.DatagramSocket.receive(DatagramSocket.java:814)at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:423)at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:212)... 239 more

When using SSH onto the host, I am also seeing it not able to resolve the dns record, not matter with 8.8.8.8 or 1.1.1.1:
Screen Shot 2021-08-20 at 19.14.33

My connection string is like: mongodb+srv://xxxx:xxxxxxxxxxx@cluster0.xe4in.mongodb.net/db?retryWrites=true&w=majority

Does anyone have any clues on this?

Thank you!

I was able to resolve the DNS entries for this cluster with a zero in cluster0 and not an upper O.

So it looks like Azure Windows does not serve you well. B-) Being Unix old bearded man, I smiled.

This editorial comment out of my chest, I notice a weird formatting in the error message. The is no space between the cluster name and the rest of the error message. May be you have backspace or other invisible character in your configuration file. May be a missing newline.

The output of nameresolver.exe seems to indicate that the cluster name is found. Try quering for TXT entry. The default might be A entry.

Hi Steeve,

Thank you for your reply!

I think the weird formatting is something with Azure logs :smile: (For example, if you scroll down to see more logs, it would have “outat”, also without space)

Also to point out that the same setting could work well on Azure Linux, but not Azure Windows. So guess it might be something related to windows haha

Also, do we need to handle specially for “mongodb+srv” for Windows?

no you do not

I would check with Azure customer service to see why.