Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketTimeoutException on MacOS >= 12.5 #260

Open
chris-cyberark opened this issue Aug 19, 2022 · 35 comments
Open

SocketTimeoutException on MacOS >= 12.5 #260

chris-cyberark opened this issue Aug 19, 2022 · 35 comments

Comments

@chris-cyberark
Copy link

chris-cyberark commented Aug 19, 2022

Maven repo dnsjava 2.0.8 Lookup.run returns SocketTimeoutException on MacOS 12.5
Using some basic DNS test code:

import org.xbill.DNS.*;
import java.util.*;
...
        Options.set("verbose", "true");
        Lookup look  = new Lookup("google.com");
        String looked = Arrays.toString(look.run());
        System.out.println(looked);

I get the result:

adding server <dns server IP>
lookup google.com. A
unknown
Sending to <dns server IP>:53
ExtendedResolver: got java.net.SocketTimeoutException

I can see in wireshark that there is a response from the DNS server, it seems it is not parsed by dnsjava:
image

@ibauersachs
Copy link
Member

dnsjava v2.0.8 is 12 (!) years old. Please use the latest version, which is currently v3.5.1. Also, if Lookup.run() fails, the result is null. Use getErrorString() to find out why the lookup failed.

@chris-cyberark
Copy link
Author

@ibauersachs Thanks for the reply, I had no idea my ver was so old!
Tried again using 3.5.1, and included getErrorString():

import org.xbill.DNS.*;
import java.util.*;
...
        Options.set("verbose", "true");
        Lookup look  = new Lookup("google.com");
        String looked = Arrays.toString(look.run());
        System.out.println(looked);
        System.out.println(look.getErrorString());

The output is now:

null
network error

Process finished with exit code 0

So... in a roundabout way the error is still the same (I think?) 'network error' does sound similar to SocketTimeoutException
But I've already confirmed that we get an answer via wireshark, is there a way to get more info about the error, or somewhere I could put a break and debug the answer processing?

Thanks

@ibauersachs
Copy link
Member

Which Java/JDK version are you using?

Please attach the debug (or trace) log output from dnsjava. It uses slf4j-api, so you can attach basically any logging framework. For your example, even slf4j-simple works. If you're using Gradle: implementation 'org.slf4j:slf4j-simple:1.7.35'

Also pass -Dorg.slf4j.simpleLogger.defaultLogLevel=debug (or trace) as a JVM argument.

This somehow looks similar to #194. However, there apparently v3.5.1 worked fine.

@chris-cyberark
Copy link
Author

Java 1.8 (Azul 1.8_345)

I took a look at #194 but its a different error to mine.
I double checked wireshark because it really looks like a networking issue, but it is the same as my original post, shows the query and the answer. It seems like somewhere it loses track of the result, I added the timing to slf4j and 5 seconds go by, but the response in wireshark is instant.

> Task :DnsApplication.main()
16 [main] DEBUG org.xbill.DNS.config.JndiContextResolverConfigProvider$InnerJndiContextResolverConfigProvider - JNDI class: javax.naming.directory.DirContext
26 [main] DEBUG org.xbill.DNS.config.ResolvConfResolverConfigProvider - Added /<dns server>:53 to nameservers
139 [main] DEBUG org.xbill.DNS.Lookup - Lookup for google.com./A, cache answer: unknown
159 [main] DEBUG org.xbill.DNS.ExtendedResolver - Sending google.com./A, id=26250 to resolver 0 (SimpleResolver [/<dns server>:53]), attempt 1 of 3
160 [main] TRACE org.xbill.DNS.Compression - Looking for google.com., found -1
161 [main] TRACE org.xbill.DNS.Compression - Adding google.com. at 12
161 [main] TRACE org.xbill.DNS.Compression - Looking for com., found -1
161 [main] TRACE org.xbill.DNS.Compression - Adding com. at 19
162 [main] TRACE org.xbill.DNS.SimpleResolver - Sending google.com./A, id=26250 to udp/<dns server>:53, query:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26250
;; flags: rd ; qd: 1 an: 0 au: 0 ad: 1 

;; OPT PSEUDOSECTION: 
; EDNS: version: 0; flags: ; udp: 1280
;; QUESTIONS:
;;	google.com., type = A, class = IN

;; ANSWERS:

;; AUTHORITY RECORDS:

;; ADDITIONAL RECORDS:


;; Message size: 39 bytes
168 [main] DEBUG org.xbill.DNS.NioClient - Starting dnsjava NIO selector thread
176 [dnsjava NIO selector] TRACE org.xbill.DNS.NioClient - 39b (UDP write):	66 8A 01 00 00 01 00 00 00 00 00 01 06 67 6F 6F 67 6C 
			65 03 63 6F 6D 00 00 01 00 01 00 00 29 05 00 00 00 00 
			00 00 00 

5182 [dnsjava NIO selector] DEBUG org.xbill.DNS.ExtendedResolver - Failed to resolve google.com./A, id=26250 with resolver 0 (SimpleResolver [/<dns server>:53]) on attempt 1 of 3, reason=java.net.SocketTimeoutException: Query timed out
5183 [dnsjava NIO selector] DEBUG org.xbill.DNS.ExtendedResolver - Sending google.com./A, id=26250 to resolver 0 (SimpleResolver [/<dns server>:53]), attempt 2 of 3
5183 [dnsjava NIO selector] TRACE org.xbill.DNS.Compression - Looking for google.com., found -1
5183 [dnsjava NIO selector] TRACE org.xbill.DNS.Compression - Adding google.com. at 12
5183 [dnsjava NIO selector] TRACE org.xbill.DNS.Compression - Looking for com., found -1
5183 [dnsjava NIO selector] TRACE org.xbill.DNS.Compression - Adding com. at 19
5183 [dnsjava NIO selector] TRACE org.xbill.DNS.SimpleResolver - Sending google.com./A, id=26250 to udp/<dns server>:53, query:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26250
;; flags: rd ; qd: 1 an: 0 au: 0 ad: 1 

;; OPT PSEUDOSECTION: 
; EDNS: version: 0; flags: ; udp: 1280
;; QUESTIONS:
;;	google.com., type = A, class = IN

;; ANSWERS:

;; AUTHORITY RECORDS:

;; ADDITIONAL RECORDS:


;; Message size: 39 bytes
5184 [dnsjava NIO selector] TRACE org.xbill.DNS.NioClient - 39b (UDP write):	66 8A 01 00 00 01 00 00 00 00 00 01 06 67 6F 6F 67 6C 
			65 03 63 6F 6D 00 00 01 00 01 00 00 29 05 00 00 00 00 
			00 00 00 

10182 [main] DEBUG org.xbill.DNS.Lookup - Lookup for google.com./A, id=26250 failed using resolver ExtendedResolver of [SimpleResolver [/<dns server>:53]]
java.io.IOException: Timed out while trying to resolve google.com./A, id=26250
	at org.xbill.DNS.Resolver.send(Resolver.java:170)
	at org.xbill.DNS.Lookup.lookup(Lookup.java:573)
	at org.xbill.DNS.Lookup.resolve(Lookup.java:653)
	at org.xbill.DNS.Lookup.run(Lookup.java:671)
	at com.dnstest.dns.DnsApplication.main(DnsApplication.java:11)

@ibauersachs
Copy link
Member

I mentioned #194 because in both cases the dnsjava's NIO implementation seems to behave differently. It's possible that the underlying async I/O on Mac is more strict than on Windows and Linux and we do something wrong.
As I don't have a modern enough Mac, this is really difficult for me to debug. Maybe @nresare can help here?

But maybe you can add some more information by:

  • Trying with Java 11
  • Taking a thread dump after the UDP message is sent, but before the resolver throws the timeout exception.

@chris-cyberark
Copy link
Author

Don't know why I didn't check this fully before, but I've found the cause; PaloAlto's GlobalProtect VPN client. Although the firewall within the VPN allows the traffic, and wireshark shows the ANSWER packet get back to my local machine at the VPN tunnel utun0 interface, there is something about the VPN OS setup that messes with DNS resolution and so it 'times out'.
Closing the VPN client fully allowed Lookup.run() to complete successfully.

I tried with Java 11 with the same results.

I'm gonna follow up with my IT/GlobalProtect team, let me know if you still want that thread dump.

@ibauersachs ibauersachs changed the title Maven repo dnsjava 2.0.8 Lookup.run returns SocketTimeoutException on MacOS 12.5 GlobalProtect VPN causes SocketTimeoutException on MacOS 12.5 Sep 8, 2022
@ibauersachs
Copy link
Member

Thanks for the follow-up. I don't think the thread dump is relevant if it works without the VPN client. I'll close this issue for now, we can always reopen if there's more to it than the VPN.

@chris-cyberark
Copy link
Author

Have had no further luck with disabling the VPN, completely removing it and any other potential blocking software seems to have no effect, the problem is back (Which makes me confused as I did see it working once and since then nothing, I have no idea why that one attempt worked.
Same issue, this time I can see on wireshark the DNS request and response go via WiFi: en0, with all VPN processes killed and double checked with ps
I upgraded to masOS 12.6 with no change.

Same result with Java 11

I'm not sure how to grab the thread dump exactly at the point the UDP request is sent, could you give me some tips?

@ibauersachs
Copy link
Member

I'm not sure how to grab the thread dump exactly at the point the UDP request is sent, could you give me some tips?

Not sure what tools you use. In IntelliJ Idea, you can click the camera symbol while debugging. Do that within the timeout, the 5s should be enough if you're prepared to click.
image

You can also create a thread dump via a Java API, e.g. by starting a thread, sleeping 1 or 2 seconds, then call:

ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] infos = bean.dumpAllThreads(true, true);
System.out.println(Arrays.stream(infos).map(Object::toString).collect(Collectors.joining()));

@nresare You have a Mac. Could you maybe do some debugging?

@ibauersachs ibauersachs changed the title GlobalProtect VPN causes SocketTimeoutException on MacOS 12.5 SocketTimeoutException on MacOS >= 12.5 Oct 2, 2022
@ibauersachs ibauersachs added the bug label Oct 2, 2022
@kevinchan-rl
Copy link

kevinchan-rl commented Jan 27, 2023

Hi, I am seeing similar problem with:

  • macOS Monterey 12.6.2
  • JDK is Amazon Corretto-17.0.4.8.1
  • netskope VPN
  • dnsjava 3.5.2
  • kotlin 1.7.21
    @Test
    fun simpleResolver() {
        val r: Resolver = SimpleResolver("8.8.8.8")
        val l = Lookup("google.com.", Type.A)
        l.setResolver(r)
        l.setCache(null)
        for (i in 0..2) {
            val results: Array<Record>? = l.run()
            if (results != null) {
                System.out.println(Arrays.asList(results))
            } else {
                System.out.println(l.getErrorString())
            }
        }
    }

has the following trace debugging output

2023-01-26 17:30:36,827 DEBUG [Test worker] org.xbill.DNS.config.JndiContextResolverConfigProvider$InnerJndiContextResolverConfigProvider: JNDI class: javax.naming.directory.DirContext
2023-01-26 17:30:36,833 DEBUG [Test worker] org.xbill.DNS.config.BaseResolverConfigProvider: Added /8.8.8.8:53 to nameservers
2023-01-26 17:30:36,836 DEBUG [Test worker] org.xbill.DNS.config.BaseResolverConfigProvider: Added thesiliconvillage.com. to search paths
2023-01-26 17:30:36,838 DEBUG [Test worker] org.xbill.DNS.config.BaseResolverConfigProvider: Added /192.168.86.1:53 to nameservers
2023-01-26 17:30:36,860 DEBUG [Test worker] org.xbill.DNS.Lookup: Lookup for google.com./A, cache answer: unknown
2023-01-26 17:30:36,864 TRACE [Test worker] org.xbill.DNS.Compression: Looking for google.com., found -1
2023-01-26 17:30:36,865 TRACE [Test worker] org.xbill.DNS.Compression: Adding google.com. at 12
2023-01-26 17:30:36,865 TRACE [Test worker] org.xbill.DNS.Compression: Looking for com., found -1
2023-01-26 17:30:36,865 TRACE [Test worker] org.xbill.DNS.Compression: Adding com. at 19
2023-01-26 17:30:36,865 TRACE [Test worker] org.xbill.DNS.SimpleResolver: Sending google.com./A, id=37672 to udp/8.8.8.8:53, query:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37672
;; flags: rd ; qd: 1 an: 0 au: 0 ad: 1 

;; OPT PSEUDOSECTION: 
; EDNS: version: 0; flags: ; udp: 1280
;; QUESTIONS:
;;	google.com., type = A, class = IN

;; ANSWERS:

;; AUTHORITY RECORDS:

;; ADDITIONAL RECORDS:


;; Message size: 39 bytes
2023-01-26 17:30:36,869 DEBUG [Test worker] org.xbill.DNS.NioClient: Starting dnsjava NIO selector thread
2023-01-26 17:30:36,882 TRACE [dnsjava NIO selector] org.xbill.DNS.NioClient: 39b (UDP write):	93 28 01 00 00 01 00 00 00 00 00 01 06 67 6F 6F 67 6C 
			65 03 63 6F 6D 00 00 01 00 01 00 00 29 05 00 00 00 00 
			00 00 00 

2023-01-26 17:30:46,906 DEBUG [Test worker] org.xbill.DNS.Lookup: Lookup for google.com./A, id=37672 failed using resolver SimpleResolver [/8.8.8.8:53]
java.io.IOException: Timed out while trying to resolve google.com./A, id=37672
	at org.xbill.DNS.Resolver.send(Resolver.java:170)
	at org.xbill.DNS.Lookup.lookup(Lookup.java:573)
	at org.xbill.DNS.Lookup.resolve(Lookup.java:653)
	at org.xbill.DNS.Lookup.run(Lookup.java:666)
	at com.ridgelineapps.utils.DnsTest.simpleResolver(DnsTest.kt:81)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
network error

dig works fine

% dig @8.8.8.8 google.com     

; <<>> DiG 9.10.6 <<>> @8.8.8.8 google.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62053
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com.			IN	A

;; ANSWER SECTION:
google.com.		300	IN	A	142.250.191.46

;; Query time: 49 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Jan 26 17:39:06 PST 2023
;; MSG SIZE  rcvd: 55

Any ideas? I am unable to disable my corporate VPN but will try to find a way to do that and try again.

@kevinchan-rl
Copy link

I took 2 thread dumps
thread_dump1.txt
thread_dump2.txt

@kevinchan-rl
Copy link

Was able to disable vpn and still doesn't work so It's not the vpn...

@ibauersachs
Copy link
Member

Thanks for the thread dumps. Looking at them confirms my suspicion that something in dnsjava's NIO usage is likely wrong. I'm not sure yet where exactly the difference between Mac and Linux/Windows is coming from here and will need to debug - which is difficult without a Mac.

@kevinchan-rl
Copy link

FWIW, also tried using JNDI and get similar timeout

    @Test
    fun jndi() {
        println(getRecords("www.google.com", "A"))
    }

    fun getRecords(hostName: String?, type: String): Array<String>? {
        val results: MutableSet<String> = TreeSet<String>()
        val envProps: Hashtable<String, String> = Hashtable<String, String>()
        envProps.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.dns.DnsContextFactory")
        envProps.put(Context.PROVIDER_URL, "dns://8.8.8.8/")
        val dnsContext: DirContext = InitialDirContext(envProps)
        val dnsEntries: Attributes? = dnsContext.getAttributes(hostName, arrayOf(type))
        if (dnsEntries != null) {
            val dnsEntryIterator: NamingEnumeration<*> = dnsEntries.get(type).getAll()
            while (dnsEntryIterator.hasMoreElements()) {
                results.add(dnsEntryIterator.next().toString())
            }
        }
        return results.toTypedArray()
    }
    DNS error
javax.naming.CommunicationException: DNS error [Root exception is java.net.SocketTimeoutException: Receive timed out]
	at platform/jdk.naming.dns@17.0.4/com.sun.jndi.dns.DnsClient.query(DnsClient.java:321)
	at platform/jdk.naming.dns@17.0.4/com.sun.jndi.dns.Resolver.query(Resolver.java:81)
	at platform/jdk.naming.dns@17.0.4/com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:434)
	at java.naming@17.0.4/com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:235)
	at java.naming@17.0.4/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:141)
	at java.naming@17.0.4/com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:129)
	at java.naming@17.0.4/javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:171)
	at app//com.ridgelineapps.utils.DnsTest.getRecords(DnsTest.kt:104)
	at app//com.ridgelineapps.utils.DnsTest.jndi(DnsTest.kt:95)
	at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base@17.0.4/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base@17.0.4/java.lang.reflect.Method.invoke(Method.java:568)
	at app//org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at app//org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at app//org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at app//org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at app//org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at app//org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base@17.0.4/java.util.ArrayList.forEach(ArrayList.java:1511)
	at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base@17.0.4/java.util.ArrayList.forEach(ArrayList.java:1511)
	at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base@17.0.4/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base@17.0.4/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.net.SocketTimeoutException: Receive timed out
	at java.base/sun.nio.ch.DatagramChannelImpl.trustedBlockingReceive(DatagramChannelImpl.java:703)
	at java.base/sun.nio.ch.DatagramChannelImpl.blockingReceive(DatagramChannelImpl.java:633)
	at java.base/sun.nio.ch.DatagramSocketAdaptor.receive(DatagramSocketAdaptor.java:240)
	at java.base/java.net.DatagramSocket.receive(DatagramSocket.java:700)
	at jdk.naming.dns/com.sun.jndi.dns.DnsClient.doUdpQuery(DnsClient.java:430)
	at jdk.naming.dns/com.sun.jndi.dns.DnsClient.query(DnsClient.java:216)
	... 93 more

@kevinchan-rl
Copy link

@ibauersachs could this be related?

https://bugs.openjdk.org/browse/JDK-8278229

@ibauersachs
Copy link
Member

I don't think so. When dnsjava fails to resolve, it's waiting on a network configuration. This might be caused by missing events, or incorrectly configured events for the selector. Also, the code from JNDI uses blocking code, dnsjava isn't. The fact that you run into a timeout with JNDI points towards a different issue, likely with your VPN or your router/ISP blocking foreign DNS servers.

@kevinchan-rl
Copy link

kevinchan-rl commented Jan 27, 2023

@ibauersachs

I deployed the code to AWS and am able to query dns from both JNDI and DnsJava so it's very possible it's something specific to my corporate laptop setup here. Or it could be something with Mac OS M1 Chipset and/or Amazon Correto 17

@chris-cyberark
Copy link
Author

Apologies on the gap in my own responses on this.

@kevinchan-rl I found similar scenarios to yours, running this on linux or Windows doesn't have the same issue.
I am using java azul zulu 8 and have tried openjdk11, so it really comes down to either a common app on our corp Macs or the MacOS itself.
To update, I'm on MacOS 13.2 with azul zulu 1.8.252 with the same issue now.

@ibauersachs is there anything you can suggest we do to help you, as you don't have a Mac available?
To follow up, here's a screenshot of pressing that camera icon during the 5 sec:

image

@ibauersachs
Copy link
Member

@chris-cyberark Thanks for the screenshot, it shows the same stacktrace like before.

If you want to help, you'll need to debug dnsjava itself while doing a simple query that you ca easily run. I have some local changes lying around with changes and debug statements to NioClient. I'll push them to a branch these days and you could start based on that.

@FehTeh
Copy link

FehTeh commented Jun 29, 2023

Hi,
I had the same "java.io.IOException: Timed out while trying to resolve" problem after upgrading from java 11 to java 17.

After all it was a firewall problem that I accidentally didn't add the java app to the allow list. Only noticed after upgrading from openjdk 17.0.6 to 17.0.7 that the mac os popup appeared again to allow network connections.

Don't know if this is the same problem but give it a try and check the mac os firewall.

@HoRg4sZ
Copy link

HoRg4sZ commented Aug 1, 2023

Hi,

Unfortunately I'm facing the same problem
M2 MacBook pro Ventura 13.5

I've a tried few things and some of them solves the issue:

  • switching to TCP - for some reason only the UDP mode times out
  • forcing Java to use ipv4 - this make it work too

Unfortunately none these are a good permanent solution for me, but it might shed some light on the root of the problem.
I've also asked some friends to try it out and it seems that on older x86 MacBooks, this is not happening. My suspicion is that it is at least partially related to the arm64 architecture in some way. Just a hunch.
I'm happy to provide some debugging info, or I can even look into the code a bit myself, albeit I'm not a network expert.

ibauersachs added a commit that referenced this issue Aug 1, 2023
@ibauersachs
Copy link
Member

ibauersachs commented Aug 1, 2023

@HoRg4sZ Thanks for the investigation and the offer to help. I'd be glad if you could dig into this. The only Mac I have is a 10+ years old Mac Mini from a junkyard that can barely open an IDE anymore. It's thus unlikely I'll be able to something about this myself.

As a starting point, you can try and build on this branch: https://github.com/dnsjava/dnsjava/tree/nio-cleanup-logging
I've added logging and I/O related things that might already fix the problem. But it's mostly untested.

Edit: I've merged this branch.

ibauersachs added a commit that referenced this issue Aug 1, 2023
@HoRg4sZ
Copy link

HoRg4sZ commented Aug 1, 2023

@ibauersachs Thanks for the quick reaction!
I've created a small example project to simply run one of the example codes:

        Record queryRecord = Record.newRecord(Name.fromString("dnsjava.org."), Type.A, DClass.IN);
        Message queryMessage = Message.newQuery(queryRecord);
        Resolver r = new SimpleResolver("8.8.8.8");
        r.setTimeout(Duration.ofSeconds(30));
        r.sendAsync(queryMessage)
                .whenComplete(
                        (answer, ex) -> {
                            if (ex == null) {
                                System.out.println(answer);
                            } else {
                                ex.printStackTrace();
                            }
                        })
                .toCompletableFuture()
                .get();

Unfortunately it does not work, not even with the branch you've shown. I've just seen that you have merged it but I guess it probably does not make a difference?
This is my console that I've got with TRACE level logging:

2023-08-01 17:21:41 [TRACE] [main] org.xbill.DNS.Compression - Looking for dnsjava.org., found -1
2023-08-01 17:21:41 [TRACE] [main] org.xbill.DNS.Compression - Adding dnsjava.org. at 12
2023-08-01 17:21:41 [TRACE] [main] org.xbill.DNS.Compression - Looking for org., found -1
2023-08-01 17:21:41 [TRACE] [main] org.xbill.DNS.Compression - Adding org. at 20
2023-08-01 17:21:41 [TRACE] [main] org.xbill.DNS.SimpleResolver - Sending dnsjava.org./A, id=1057 to udp/8.8.8.8:53, query:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1057
;; flags: rd ; qd: 1 an: 0 au: 0 ad: 1 

;; OPT PSEUDOSECTION: 
; EDNS: version: 0; flags: ; udp: 1280
;; QUESTIONS:
;;	dnsjava.org., type = A, class = IN

;; ANSWERS:

;; AUTHORITY RECORDS:

;; ADDITIONAL RECORDS:


;; Message size: 40 bytes
2023-08-01 17:21:41 [DEBUG] [main] org.xbill.DNS.NioClient - Starting dnsjava NIO selector thread
2023-08-01 17:21:41 [TRACE] [dnsjava NIO selector] org.xbill.DNS.NioUdpClient - Registering OP_READ for transaction with id 1057
2023-08-01 17:21:41 [TRACE] [dnsjava NIO selector] org.xbill.DNS.NioClient - 40b (UDP write, transaction id=1057):	04 21 01 00 00 01 00 00 00 00 00 01 07 
					64 6E 73 6A 61 76 61 03 6F 72 67 00 00 
					01 00 01 00 00 29 05 00 00 00 00 00 00 
					00 

java.util.concurrent.CompletionException: java.net.SocketTimeoutException: Query timed out
	at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
	at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
	at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:957)
	at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:940)
	at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488)
	at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1990)
	at org.xbill.DNS.NioUdpClient$Transaction.completeExceptionally(NioUdpClient.java:144)
	at org.xbill.DNS.NioUdpClient$Transaction.access$200(NioUdpClient.java:82)
	at org.xbill.DNS.NioUdpClient.checkTransactionTimeouts(NioUdpClient.java:75)
	at org.xbill.DNS.NioClient.runSelector(NioClient.java:111)
	at java.lang.Thread.run(Thread.java:750)
Caused by: java.net.SocketTimeoutException: Query timed out
	... 3 more
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.SocketTimeoutException: Query timed out
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)
	at com.ssn.amm.Main.main(Main.java:34)
Caused by: java.net.SocketTimeoutException: Query timed out
	at org.xbill.DNS.NioUdpClient.checkTransactionTimeouts(NioUdpClient.java:75)
	at org.xbill.DNS.NioClient.runSelector(NioClient.java:111)
	at java.lang.Thread.run(Thread.java:750)
2023-08-01 17:22:12 [DEBUG] [dnsjava NIO selector] org.xbill.DNS.NioClient - dnsjava NIO selector thread stopped

I can also see with Wireshark, that the response is actually coming (in time) to my machine from the DNS server. I can copy the packets too if you are interested.
Oh and if I set the useTCP flag on the resolver to true, everything works.

@ibauersachs
Copy link
Member

Thanks for the diagnosis, which is consistent what others have seen. Can you try playing around with the NIO channel? I assume this has something to do with how MacOS handles poll/epoll (see e.g. https://daniel.haxx.se/blog/2016/10/11/poll-on-mac-10-12-is-broken/).

@dsukhoroslov
Copy link

I have the same issue with my Mac 13.6, Java 17.0.8. I see it only when I specify particular DNS server address when creating SimpleResolver. If no DNS address provided, then it works fine. dig works fine from terminal with and without DNS address.

@ibauersachs
Copy link
Member

I've now tried to debug this with my colleague @mkretz from @bespinian, on MacOS 14.6 with Java 11.0.21 (aarch). We were unable to reproduce the issue.

Sorry, but I'm lost here. Someone who still experiences this issue needs to debug this. Also, #260 (comment) makes me wonder whether this really is a dnsjava issue or something in either the JVM or some other VPN or firewall tool/extension that blocks the Java process from getting the reply.

@nicholas-signal
Copy link

I can consistently reproduce this on macOS 14.2 with dnsjava 3.5.3, and similarly, setting TCP to true fixes it for me as well. This behavior extends at least as far back as dnsjava 2.1.9. Where should I start with debugging?

@ibauersachs
Copy link
Member

@nicholas-signal Create simple class that you can easily execute, like in #260 (comment). Then try to debug in NioClient and NioUdpClient if you get any events at all, try if you need to modify the selection keys. You could also try to create a very basic UDP client outside of dnsjava, send the bytes for a simple query (e.g. dumped by a previous request from dnsjava) and verify that you're actually getting results back.

@mohamed-elhar
Copy link

mohamed-elhar commented Jan 5, 2024

Hi!
I'm using the latest version (3.5.3) to performing NAPTR query (reversed number separated by dots and concatenated with dns suffix) e.g "6.5.4.3.2.1.example.org", and I'm facing an issue with the timeout.
when I set the timeout to 2 sec for example and I send a wrong query to dns server the timeout is not respected and the resolver used the default timeout 10 sec.
here is below my code:

        String NAPTRQuery = "6.5.4.3.2.1.example.org";
        Resolver resolver = new SimpleResolver(dnsServerIP);
        resolver.setPort(dnsServerPort);
        resolver.setTimeout(Duration.ofMillis(2000L)); 
        Lookup lookup = new Lookup(NAPTRQuery , Type.NAPTR, DClass.IN);
        lookup.setResolver(resolver);
        lookup.setCache(new Cache());
        Record[] records = lookup.run();

Can you please help?
Thanks in advance.

@ibauersachs
Copy link
Member

@mohamed-elhar You seem to have a different issue. Also, your example runs in exactly 2s when I specify an invalid IP address as the dns server. If yours is running longer, then you probably have one or more searchPaths. Use absolute names if you can.

@mohamed-elhar
Copy link

Thank you @ibauersachs for you response.
Exactly, I've logged the searchPath using ResolveConfig.searchPath() and I confirm that I have multiple ones.
Is there any option to not use the default paths mentioned in the /etc/resolv.conf and forcing only the dns server provided in the Resolver constructor?

@ibauersachs
Copy link
Member

You can clear the path on your resolver instance, otherwise have a look at the config properties as described in the readme.

@mohamed-elhar
Copy link

mohamed-elhar commented Jan 8, 2024

I've some problem with Cache mechanism, I set the max records and the ttl but each time I send an enum query I visualize in the dns server that a new query is arriving. Here is bellow the code used:

Cache cache = new Cache(DClass.IN);
cache.setMaxCache(5);
cache.setMaxNCache(5);
cache.setMaxEntries(1000);
Lookup.setDefaultCache(cache, cache.getDClass()); 
Lookup lookup = new Lookup(NAPTRQuery, Type.NAPTR, DClass.IN);
Record[] records = lookup.run();

@ibauersachs
Copy link
Member

Your problem has nothing to do with the Mac issue here. Please open separate issues so that people following here are not further distracted.

@osxhacker
Copy link

Hi @ibauersachs ,

Here is a follow-up for anyone encountering this issue as of today, along with what rectified this problem.

Problem Verification

I ran into the same problem today using the following:

$ uname -mrs
Darwin 23.1.0 arm64

$ java -version
openjdk version "19.0.2" 2023-01-17
OpenJDK Runtime Environment (build 19.0.2+7-44)
OpenJDK 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)

All dnsjava tests passed when mvn test was executed on the release/3.5.x branch. However, ResolveExample.java exhibited the query timeout symptoms both when SimpleResolver and ValidatingResolver were used.

Resolution

Downloading OpenJDK 21 for macOS / AArch64, installing it, then using it to do a full recompile resulted in ResolveExample.java running without exception. The output also appeared to be in order.

Rebuilding the project I am working on with JDK v21 which uses dnsjava and running its integration tests also no longer experience "query timeouts" and performed a successful query (which it had not before).

The only change in system environment was installing and then using JDK v21.

Therefore, I believe updating to:

$ java -version
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-58)
OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)

Rectified this issue. Should I observe this to not be the case, I will update this comment accordingly.

It is unknown if JDK v20 also rectifies this issue as I did not test that distribution.

Thanks for your work on this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants