Repository navigation
[Issue-3456] Apply systemPropertyVariables before the fork initializes networking - #3467
Merged
Merged
Conversation
β¦s networking ForkedBooter#setupBooter read the booter properties file through java.nio.file.Files before it applied the effective system properties. On every platform that path initializes sun.nio.ch.IOUtil, whose static initializer loads the native "net" library; libnet's JNI_OnLoad reads java.net.preferIPv4Stack once and caches the result in ipv6_available. Any value coming from systemPropertyVariables therefore arrived too late and was silently ignored, and the fork kept running on the IPv6 stack. The nio call was introduced in 3.6.0 (0c24343, apache#3179), which replaced FileInputStream with Files.newInputStream; before that no java.nio channel was touched during boot and the property took effect. Apply the effective system properties as the very first statement of setupBooter and read the booter properties file with FileInputStream again, so the ordering guarantee does not depend on which java.io/java.nio API a later change happens to pick. Note that Windows cannot be fixed this way: sun.nio.fs.WindowsNativeDispatcher loads "net" itself ("nio.dll has dependency on net.dll") and any jar on the class path triggers it during JVM start-up, before main. The new integration test is skipped there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
olamy
reviewed
Sep 10, 2026
| } | ||
|
|
||
| /** | ||
| * Deliberately uses {@link FileInputStream} instead of {@link java.nio.file.Files#newInputStream}: the latter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3456.
What
systemPropertyVariableswere applied too late in the forked JVM, sojava.net.preferIPv4Stack(andjava.net.preferIPv6Addresses) were silently ignored and the fork kept running on the IPv6 stack. Reported against 3.6.0, hit by Hadoop in HADOOP-19964.Why
ForkedBooter#setupBooterread the booter properties file before applying the effective system properties:That was harmless while the file was read with
FileInputStream. In 3.6.0, commit 0c24343 (#3179) changedcreateSurefirePropertiesIfFileExiststojava.nio.file.Files.newInputStream, and that call chain is:Files.newInputStreamβFileChannelβsun.nio.ch.UnixFileDispatcherImpl(WindowsFileDispatcherImpl) βstatic { IOUtil.load(); }βBootLoader.loadLibrary("net")libnet's
JNI_OnLoadcallsBoolean.getBoolean("java.net.preferIPv4Stack")once and caches the answer inipv6_available. So by the timesetSystemPropertiesran, the networking stack was already fixed, and the property had no effect β silently, and only on machines that actually have IPv6.Ordinary
java.nio.filecalls are not enough to trigger this on Unix βsun.nio.fs.UnixNativeDispatcherloads only"nio"β which is why the file-reading path specifically is what regressed.How
setSystemProperties(...)is now the first statement ofsetupBooter, before anything else in the fork runs.createSurefirePropertiesIfFileExistsusesFileInputStreamagain, so the guarantee does not silently depend on which java.io/java.nio API a future change happens to pick. Both spots carry a comment explaining why.Platform caveat
Windows cannot be fixed this way and never worked, including before 3.6.0.
sun.nio.fs.WindowsNativeDispatcherloads the native library itself:Opening any jar on the class path reaches that (
ZipFile$Sourcestats the file throughjava.nio.file), sojava.net.preferIPv4Stackis already frozen beforemainruns. Users who need it on Windows have to pass-Djava.net.preferIPv4Stack=trueviaargLine. The new integration test is skipped on Windows for this reason.Tests
ForkedBooterMockTest.shouldReadSurefirePropertiesWithoutInitializingNioβ pins the booter properties file to a non-NIO stream. Fails on the 3.6.0 code, passes with this change.Surefire3456PreferIPv4StackITβ runs a project configured with<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>insystemPropertyVariablesand asserts the fork really is on the IPv4 stack (noInet6Addressreported byNetworkInterface). Skipped on Windows per the caveat above.Verified locally:
mvn clean installis green, andForkedBooterMockTestfails as expected when theFiles.newInputStreamcall is put back. The new IT was exercised on Windows only, where it fails without the fix on the property-propagation path and is skipped by the OS assumption in its final form β I have no Linux box here, so the IT's positive path needs CI to confirm.Checklist
Each commit in the pull request should have a meaningful subject line and body.
Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
Run
mvn clean installto make sure basic checks pass. A more thorough check will be performed on your pull request automatically.You have run the integration tests successfully (
mvn -Prun-its clean install). β only the new IT was run locally; the full suite was not.I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
π€ Generated with Claude Code