Java application gets error java.net.SocketException: Protocol family unavailable

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL)
  • Apache Tomcat, Red Hat JBoss Web Server (JBoss Web)
  • OpenJDK, Oracle Java
  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7
  • Internet Protocol version 6 (IPv6) disabled at the kernel level

Issue

  • Java application does not start and this error is in logging the exception java.net.SocketException: Protocol family unavailable

      Caused by: java.net.SocketException: Protocol family unavailable
              at java.net.PlainSocketImpl.socketBind(Native Method)
              at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
              at java.net.ServerSocket.bind(ServerSocket.java:375)
              at java.net.ServerSocket.<init>(ServerSocket.java:237)
              at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:55)
              at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:403)
              at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:650)
              at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
              at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
              ... 13 more
    

    Or

      Caused by: java.net.SocketException: Protocol family unavailable
              at sun.nio.ch.Net.bind0(Native Method)
              at sun.nio.ch.Net.bind(Net.java:433)
              at sun.nio.ch.Net.bind(Net.java:425)
              at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
              at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
              at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:178)
              at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:303)
              at org.wildfly.extension.undertow.HttpListenerService.startListening(HttpListenerService.java:106)
              at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:199)
              ... 8 more='
    
  • When enabling IPv6 in operating-system, JBoss EAP adopting the IPv6 configuration automatically and disables at operating-system, JBoss EAP is crashing. Need to disable IPv6 permanently in JBoss EAP even operating-system has enabled or disabled IPv6 at operating-system level.

Resolution

Root Cause

For JBoss EAP, when it tries to bind to all interfaces, or 0.0.0.0, if preferIPv4Stack=false or preferIPv6Address=true, the config will end up throwing all of the relevant IPv4 addresses due to the way the config is managed, see Content from issues.jboss.org is not included.JBEAP-17662 preferIPv6Addresses and preferIPv4Stack System Properties are Mishandled in the Config.

Normally, it would still drop to IPv4, but if the IPv6 protocol is completely disabled, it throws the exception.

There is a bug fix related to EAP processing -Djava.net.preferIPv4Stack and -Djava.net.preferIPv6Addresses that may be related and This content is not included.JBEAP-17662 was fixed in 7.2.5.

Diagnostic Steps

  1. Check if IPv6 is disabled in /etc/sysctl.conf or one of the files in /etc/sysctl.d/. Look for the settings below. The Linux kernel uses two settings for disabling IPv6 and 1 means the protocol is disabled.

    # sysctl net.ipv6.conf.all.disable_ipv6
    net.ipv6.conf.all.disable_ipv6 = 1
    # sysctl net.ipv6.conf.default.disable_ipv6
    net.ipv6.conf.all.disable_ipv6 = 1
    
  2. Check if IPv6 is disabled in the currently running system by running the following commands as root.

    Until RHEL 6
    # ifconfig -a | grep inet6
    RHEL 7 onwards
    # ip addr show | grep net6
    
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.