java.net.SocketException: An invalid argument was supplied

JDK Bug System | Webbug Group | 2 years ago
  1. 0

    FULL PRODUCT VERSION : java version "1.7.0_72" Java(TM) SE Runtime Environment (build 1.7.0_72-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode) ADDITIONAL OS VERSION INFORMATION : Windows Server 2008 R2 (6.1.7601), also repeated on Windows 7 64-bit (also 6.1.7601). EXTRA RELEVANT SYSTEM CONFIGURATION : IPv6 is disabled in the network adapter. A DESCRIPTION OF THE PROBLEM : This looks like it may be a recurrence of JDK-6458027 or something similar. After reading that bug report the same workaround of using -Djava.net.preferIPv4Stack=true resolves this issue. JBoss JGroups began throwing a SocketException on java.net.MulticastSocket.setInterface when we upgraded from 7u67 to 7u71 (64 bit JRE). Confirmed problem is repeatable on 7u72 as well. Looking at the JGroups code I was able to repeat the problem with a simple sample program pasted below. After compiling this I can call it passing my systems public IP address as an argument and it runs fine on 7u65 or 7u67 but when I use 7u71 or 7u72 to run it I get the exception. Searching for a bug I found the one listed above that was resolved some time ago but as mentioned above the same workaround works. When I use the preferIPv4Stack=true property it runs fine on all versions. Sample application to reproduce issue: --------------------------------------------------------- import java.net.*; public class Socket { public static void main(String[] args) { try { String bind_ip = args[0]; System.out.println("Getting socket on: "+bind_ip+"\n"); InetAddress bind_addr = InetAddress.getByName(bind_ip); int mcast_port = 35000; MulticastSocket mcast_sock = new MulticastSocket(mcast_port); mcast_sock.setInterface(bind_addr); } catch (Exception e) { System.out.println("Exception: "+e+"\n"); } } } ---------------------------------------------- Full stack trace: java.net.SocketException: An invalid argument was supplied at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145) at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310) at java.net.MulticastSocket.setInterface(MulticastSocket.java:467) at Socket.main(Socket.java:14) REGRESSION. Last worked in version 7u67 ADDITIONAL REGRESSION INFORMATION: java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Use the following sample application and pass the systems public IP address on a Windows Server 2008 R2 or Windows 7 64-bit system with IPv6 disabled (un-checked) on the public adapter. You can't use localhost, it will work fine. import java.net.*; public class Socket { public static void main(String[] args) { try { String bind_ip = args[0]; System.out.println("Getting socket on: "+bind_ip+"\n"); InetAddress bind_addr = InetAddress.getByName(bind_ip); int mcast_port = 35000; MulticastSocket mcast_sock = new MulticastSocket(mcast_port); mcast_sock.setInterface(bind_addr); } catch (Exception e) { System.out.println("Exception: "+e+"\n"); } } } EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - No exception thrown by the setInterface method. Sample application should return with no error. ACTUAL - The following stack trace is thrown: java.net.SocketException: An invalid argument was supplied at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145) at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310) at java.net.MulticastSocket.setInterface(MulticastSocket.java:467) at Socket.main(Socket.java:14) ERROR MESSAGES/STACK TRACES THAT OCCUR : java.net.SocketException: An invalid argument was supplied at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method) at java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145) at java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310) at java.net.MulticastSocket.setInterface(MulticastSocket.java:467) at Socket.main(Socket.java:14) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- Use the following sample application and pass the systems public IP address on a Windows Server 2008 R2 or Windows 7 64-bit system with IPv6 disabled (un-checked) on the public adapter. You can't use localhost, it will work fine. import java.net.*; public class Socket { public static void main(String[] args) { try { String bind_ip = args[0]; System.out.println("Getting socket on: "+bind_ip+"\n"); InetAddress bind_addr = InetAddress.getByName(bind_ip); int mcast_port = 35000; MulticastSocket mcast_sock = new MulticastSocket(mcast_port); mcast_sock.setInterface(bind_addr); } catch (Exception e) { System.out.println("Exception: "+e+"\n"); } } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Use -Djava.net.preferIPv4Stack=true

    JDK Bug System | 2 years ago | Webbug Group
    java.net.SocketException: An invalid argument was supplied
  2. 0

    jSLP / Discussion / Open Discussion: bad argument for IP_MULTICAST_IF: address not bound to any interface

    sourceforge.net | 11 months ago
    java.net.SocketException: bad argument for IP_MULTICAST_IF: address not bound to any interface
  3. 0

    The cajo project: Users: Multicast error — Project Kenai

    java.net | 11 months ago
    java.net.SocketException: bad argument for IP_MULTICAST_IF: address not bound to any interface
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Start Elastic Node without network link

    GitHub | 6 years ago | dadoonet
    org.elasticsearch.discovery.DiscoveryException: Failed to setup multicast socket
  6. 0

    SLP Java function causing SocketException due to IP_MULTICAST_IF

    Stack Overflow | 5 years ago | devonbleibtrey
    java.net.SocketException: bad argument for IP_MULTICAST_IF: address not bound to any interface

    5 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.net.SocketException

      An invalid argument was supplied

      at java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption()
    2. Java RT
      MulticastSocket.setInterface
      1. java.net.TwoStacksPlainDatagramSocketImpl.socketNativeSetOption(Native Method)
      2. java.net.TwoStacksPlainDatagramSocketImpl.socketSetOption(TwoStacksPlainDatagramSocketImpl.java:145)
      3. java.net.AbstractPlainDatagramSocketImpl.setOption(AbstractPlainDatagramSocketImpl.java:310)
      4. java.net.MulticastSocket.setInterface(MulticastSocket.java:467)
      4 frames
    3. Unknown
      Socket.main
      1. Socket.main(Socket.java:14)
      1 frame