Skip to content

RATIS-2744. Add -Djava.net.preferIPv4Stack=true to root pom file for tests - #1637

Open
amaliujia wants to merge 1 commit into
apache:masterfrom
amaliujia:RATIS-2744
Open

amaliujia wants to merge 1 commit into
apache:masterfrom
amaliujia:RATIS-2744

Conversation

@amaliujia

@amaliujia amaliujia commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

When no host is configured, the gRPC and Netty servers build their bind address with new InetSocketAddress(port), which resolves to the IPv6 wildcard ::. On machines without IPv6 support, such as the GitHub Actions Ubuntu runners, the native epoll transport can't bind to that address, so the server fails to start.

Try adding -Djava.net.preferIPv4Stack=true to root pom file for tests so have tests use ipv4.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-2744

Discovered from the github job: https://github.com/apache/ratis/actions/runs/36123180483/job/108033212253?pr=1614 with the following tracestack:

Caused by: org.apache.ratis.util.ExitUtils$ExitException: Failed to start Grpc server
at org.apache.ratis.util.ExitUtils.terminate(ExitUtils.java:141)
at org.apache.ratis.util.ExitUtils.terminate(ExitUtils.java:151)
at org.apache.ratis.grpc.server.GrpcServicesImpl.startImpl(GrpcServicesImpl.java:393)
at org.apache.ratis.util.LifeCycle.startAndTransition(LifeCycle.java:280)
at org.apache.ratis.server.RaftServerRpcWithProxy.start(RaftServerRpcWithProxy.java:72)
at org.apache.ratis.server.impl.RaftServerProxy.startImpl(RaftServerProxy.java:416)
at org.apache.ratis.util.LifeCycle.startAndTransition(LifeCycle.java:280)
at org.apache.ratis.server.impl.RaftServerProxy.start(RaftServerProxy.java:409)
at org.apache.ratis.server.impl.MiniRaftCluster.startServers(MiniRaftCluster.java:466)
at org.apache.ratis.server.impl.MiniRaftCluster.start(MiniRaftCluster.java:340)
at org.apache.ratis.server.impl.MiniRaftCluster$Factory$Get.runWithNewCluster(MiniRaftCluster.java:144)
at org.apache.ratis.server.impl.MiniRaftCluster$Factory$Get.runWithNewCluster(MiniRaftCluster.java:124)
at org.apache.ratis.datastream.DataStreamCommandE2ETestCases.testStreamCommand(DataStreamCommandE2ETestCases.java:66)
... 3 more
Caused by: java.io.IOException: Failed to bind to address ::/[0:0:0:0:0:0:0:0]:15002
at org.apache.ratis.thirdparty.io.grpc.netty.NettyServer.start(NettyServer.java:347)
at org.apache.ratis.thirdparty.io.grpc.internal.ServerImpl.start(ServerImpl.java:187)
at org.apache.ratis.thirdparty.io.grpc.internal.ServerImpl.start(ServerImpl.java:94)
at org.apache.ratis.grpc.server.GrpcServicesImpl.startImpl(GrpcServicesImpl.java:391)
... 13 more
Caused by: org.apache.ratis.thirdparty.io.netty.channel.unix.Errors$NativeIoException: bind(..) failed with error(-97): Address family not supported by protocol

How was this patch tested?

Existing test

@amaliujia

Copy link
Copy Markdown
Contributor Author

We could make this for test only though.

*/
static InetSocketAddress createBindSocketAddress(String host, int port) {
return host == null || host.isEmpty() ?
createSocketAddrForHost(WILDCARD_ADDRESS, port) : createSocketAddrForHost(host, port);

@szetszwo szetszwo Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amaliujia , some questions/comments:

  • Could we use JVM option -Djava.net.preferIPv4Stack=true ?

  • Some systems may support IPv6 only. Then, this may not work.

  • I suggest to try-catch the binding methods such as ServerBuilder.forPort(port). When it fails, fall back to IPv4 wildcard.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. try -Djava.net.preferIPv4Stack=true first.

@amaliujia amaliujia changed the title RATIS-2744. Bind gRPC and Netty servers to the IPv4 wildcard when no host is configured RATIS-2744. Add -Djava.net.preferIPv4Stack=true to root pom file for tests Oct 15, 2026

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good

@adoroszlai , could you also take a look?

@adoroszlai

Copy link
Copy Markdown
Contributor

Thanks @amaliujia for working on this.

The problem appears only in #1614, which bumps maven-apache-parent, which in turn bumps maven-surefire-plugin to 3.6.0. Adding preferIPv4Stack fixes the IP problem, but a different, Mockito-related error appears in several tests (but fewer than the IP issue), see below. We need this patch only if upgrading surefire, but this in itself is not enough in that case.

Therefore I propose the following:

  • introduce this workaround (or preferably fix the root cause) only when upgrading surefire (via parent POM), otherwise it is a no-op change
  • defer upgrade of parent POM until we can fix all 3 problems (2 test issues + Rat java version compatibility)

Of course should these 2 problems turn out to be Surefire bugs, we can upgrade as soon as they are fixed in Surefire.

Mockito error:

[ERROR] Tests run: 16, Failures: 0, Errors: 16, Skipped: 0, Time elapsed: 0.728 s <<< FAILURE! -- in org.apache.ratis.grpc.server.TestGrpcLogAppenderCallbacks
[ERROR] org.apache.ratis.grpc.server.TestGrpcLogAppenderCallbacks.testTimeout -- Time elapsed: 0.016 s <<< ERROR!
java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
	at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:84)
	at jdk.proxy2/jdk.proxy2.$Proxy21.isTypeMockable(Unknown Source)
	at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:78)
	at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
	at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:267)
	at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:234)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:86)
	at org.mockito.Mockito.mock(Mockito.java:2037)
	at org.mockito.Mockito.mock(Mockito.java:1952)
	at org.apache.ratis.grpc.server.TestGrpcLogAppenderCallbacks.<init>(TestGrpcLogAppenderCallbacks.java:84)
	...
Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in java.lang.CompoundEnumeration@1fde4f40
	at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:56)
	at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:65)
	at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:50)
	at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:27)
	at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:22)
	at org.mockito.internal.MockitoCore.<clinit>(MockitoCore.java:73)
	at org.mockito.Mockito.<clinit>(Mockito.java:1669)
	... 6 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:74)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
	at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:51)
	... 12 more
Caused by: org.mockito.exceptions.base.MockitoInitializationException: 
Could not initialize inline Byte Buddy mock maker.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants