When IPv6 is enabled, the JDK uses dual stack IPv4/IPv6 sockets
by default. Binding, connecting, or sending datagrams uses
IPv4-mapped IPv6 addresses in this case.
On some hosts running macOS version 15.6.x and above, and macOS
26, it has been observed that when a datagram socket bound to a
IPv4 mapped IPv6 address sends a packet, either using the
java.net.DatagramSocket or
java.nio.channels.DatagramChannel APIs, then the first
packet is lost and never gets delivered. A second invocation of
send on the same socket, even to the same destination
address, correctly delivers the packet and it is received by the
recipient.
A bug has been filed with Apple (feedback issue id FB20302424)
seeking their assistance. The issue is currently unresolved.
Until the issue is resolved, there are a couple of workarounds
that applications can consider:
-
If using IPv4 is acceptable, then the java command
can be launched with -Djava.net.preferIPv4Stack=true
to use IPv4 sockets by default.
-
If using -Djava.net.preferIPv4Stack=true is not
acceptable, a more local workaround can be applied by changing the
application code to create a
java.nio.channels.DatagramChannel with
java.net.StandardProtocolFamily.INET as the protocol
family and then bind the channel to a IPv4 address.