Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8368741

[macos] The first datagram sent from a DatagramSocket or DatagramChannel is lost when IPv6 is enabled

XMLWordPrintable

      The JDK, by default, uses dual IPv4/IPv6 sockets on systems that have IPv6 enabled. Binding, connecting and send uses IPv4-mapped IPv6 addresses.

      On macos 15.6.x and 15.7 (and even 26), it has been observed that a datagram socket when bound to a IPv4 mapped IPv6 address sends a packet, either using the "java.net.DatagramSocket" or "java.nio.channels.DatagramChannel" Java SE APIs, then the first packet is lost and never gets delivered. The native syscall, which these API implementations invoke, gives no indication of the failure to send the packet and returns normally without any error. A second invocation of send() on the same socket (even against the same destination address) correctly delivers the packet and it is received by the recipient.

      macos system level logs show that there's some error deep within the macos internals during the first send():

      default kernel cfil_hash_entry_log:6088 <CFIL: Error: sosend_reinject() failed>:
                    [81243 a.out] <UDP(17) out so 59faaa5dbbcef55d 127846646561221313 127846646561221313 age 0>
                    lport 65055 fport 65055 laddr 192.168.10.12 faddr 192.168.10.12 hash 201AAC1
      default kernel cfil_service_inject_queue:4472 CFIL: sosend() failed 22

      A reproducer is attached which uses DatagramSocket API to send() a message. It does this twice. The first sent message is never received whereas the second one is. The issue can similarly be reproduced using DatagramChannel API.

      Run the attached reproducer as:

      java Send.java

      The output will look something like:

      Process id: 12355 running test against Java version 25 (25+36-3489)
      java.net.Inet4Address
      ---- Attempt 1 ----
      java.net.Inet4Address -> java.net.Inet4Address
      sending [49, 50, 51, 52, 53] from /192.168.10.23:56787 to a-mac/192.168.10.23:56787
      receive timed out: java.net.SocketTimeoutException: Receive timed out
      ---------------------
      ---- Attempt 2 ----
      java.net.Inet4Address -> java.net.Inet4Address
      sending [49, 50, 51, 52, 53] from /192.168.10.23:56787 to a-mac/192.168.10.23:56787
      successfully received [49, 50, 51, 52, 53] from /192.168.10.23:56787
      ---------------------
      Exception in thread "main" java.lang.AssertionError: Test FAILED
          at Send.test(Send.java:38)
          at Send.main(Send.java:9)

      The issue is reproducible against all Java versions including Java 8.

            jpai Jaikiran Pai
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: