Java application gets error java.net.SocketException: Protocol family unavailable
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 unavailableCaused 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 moreOr
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
IPv6in operating-system, JBoss EAP adopting theIPv6configuration automatically and disables at operating-system, JBoss EAP is crashing. Need to disableIPv6permanently in JBoss EAP even operating-system has enabled or disabledIPv6at operating-system level.
Resolution
-
JBoss EAP
This seems to only happen when either
java.net.preferIPv4Stack=falseorjava.net.preferIPv6Addresss=trueand when binding to address 0.0.0.0. Users can remove the system properties. There is also an issue in the works to correct this. See Root Cause. -
Apache Tomcat, Red Hat JBoss Web
In case it is not possible to activate
IPv6, then it is needed to add configuration to allow Apache Tomcat to only useIPv4. Please see How do I restrict Apache Tomcat to listening onlyIPv4address? -
Enable
IPv6See How do I disable or enable the
IPv6protocol in Red Hat Enterprise Linux?
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
-
Check if
IPv6is disabled in/etc/sysctl.confor one of the files in/etc/sysctl.d/. Look for the settings below. The Linux kernel uses two settings for disablingIPv6and1means 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 -
Check if
IPv6is 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
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.