Submitted to Oracle, but posted here too, because I'm not sure if this bug will make its way to the OpenJDK bug tracker.
$ java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
$ javac -version
javac 1.8.0_121
(You might have to run tshark and kill as root.)
$ javac MakeTwoDnsRequests.java
$ tshark -i any -f "src port 53" -Y "dns.qry.type eq 1" -n -T fields -e dns.qry.name -e dns.a > without-jmx.txt 2>/dev/null &
[1] 17460
$ java MakeTwoDnsRequests
$ kill 17460
$ cat without-jmx.txt
www.example.com 93.184.216.34
www.example.com 93.184.216.34
$
$ tshark -i any -f "src port 53" -Y "dns.qry.type eq 1" -n -T fields -e dns.qry.name -e dns.a > with-jmx.txt 2>/dev/null &
[1] 17495
$ java -Dcom.sun.management.jmxremote MakeTwoDnsRequests
$ kill 17495
$ cat with-jmx.txt
I expect two DNS requests are sent:
$ cat with-jmx.txt
www.example.com 93.184.216.34
www.example.com 93.184.216.34
But actually one DNS request is sent!
$ cat with-jmx.txt
www.example.com 93.184.216.34
For Hotspot, specify sun.net.inetaddr.ttl=0
when starting the JVM:
$ java -Dsun.net.inetaddr.ttl=0 -Dcom.sun.management.jmxremote MakeTwoDnsRequests
networkaddress.cache.ttl
is cached in the static initializer of InetAddressCachePolicy[1]. JMX presumably causes InetAddressCachePolicy's static initialiser to be executed, before main gets a chance to set networkaddress.cache.ttl
.
Oracle bug with internal ID 9047808.