JDK-8328615 : Various java.net and java.nio tests fail with Invalid argument: setsockopt on Ipv6 able machine without Ipv6 interface
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows
  • CPU: x86
  • Submitted: 2024-03-20
  • Updated: 2024-06-04
Related Reports
Relates :  
Description
On one of our Windows machines  (Windows Server 2022) the following error occurs :
java/net/DatagramSocket/DatagramSocketExample.java

java.net.SocketException: Invalid argument: setsockopt
	at java.base/sun.nio.ch.Net.setInterface6(Native Method)
	at java.base/sun.nio.ch.DatagramChannelImpl.setOption(DatagramChannelImpl.java:381)
	at java.base/sun.nio.ch.DatagramSocketAdaptor.setOption(DatagramSocketAdaptor.java:379)
	at java.base/java.net.DatagramSocket.setOption(DatagramSocket.java:1215)
	at DatagramSocketExample.test(DatagramSocketExample.java:132)
	at DatagramSocketExample.main(DatagramSocketExample.java:83)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138)
	at java.base/java.lang.Thread.run(Thread.java:1575)

Same error pattern/similar exception can be seen in the following tests :

java/net/DatagramSocket/DatagramSocketExample.java
java/net/DatagramSocket/DatagramSocketMulticasting.java
java/net/MulticastSocket/JoinLeave.java
java/net/MulticastSocket/IPMulticastIF.java
java/net/MulticastSocket/NoSetNetworkInterface.java
java/net/MulticastSocket/SetGetNetworkInterfaceTest.java
java/net/SocketOption/OptionsTest.java
java/nio/channels/DatagramChannel/AdaptorMulticasting.java
java/nio/channels/DatagramChannel/Loopback.java

Seems the machine, "lost" Ipv6 interfaces, ipconfig does not show it any more (the machine and OS itself supports Ipv6 "in theory").
Looks like our checks in the test code do not cover this fully .

Comments
You can reproduce this easily by just disabling IPv6 in the legacy Network properties dialog, which seems to have the effect of removing all IPv6 addresses from all interfaces. Not sure what we can do about it though, as the OS still supports IPv6. We test this at startup by just creating an AF_INET6 socket and this succeeds. it would be harder and less reliable to base support for IPv6 on whether IPv6 addresses are currently available or not. Having said that, this situation seems to affect IPv4 functionality as well. So, a bit more investigation is needed. The issue is long present by the way and is not specific to 23.\ Seems to be a duplicate of JDK-8272476. Will close this one.
04-06-2024

Hi Michael, maybe we can do something better in the tests / test framework to check for such cases/such setup . Or improve the exception if this is easily possible , e.g. instead of java.net.SocketException: Invalid argument: setsockopt something like (or even more details ?) java.net.SocketException: Invalid argument: setsockopt failed, your IPv6 functionality was disabled
21-03-2024

Not sure that this is a configuration we need to support. I guess it is possible to create IPv6 sockets, but IPv6 is (partly) disabled. This should be verified though.
21-03-2024

seems IPv6 was disabled on the test machine by setting registry information : https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-ipv6-in-windows Location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters\ Name: DisabledComponents (Disable IPv6)
21-03-2024