ensure order of jvm options from file and env vars is respected (#15997) (#16004)

Co-authored-by: Andrea Selva <selva.andre@gmail.com>
(cherry picked from commit 43614ede50)

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2024-03-12 09:21:45 +00:00 committed by GitHub
parent 17784fd09b
commit e5b988fed2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -198,7 +198,9 @@ public class JvmOptionsParser {
if (maxOrderAlreadyContained) {
return options;
}
final Set<String> acc = new HashSet<>(options);
// Order is important because LS_JAVA_OPTS is added last and must take precedence
// over settings in jvm.options
final Set<String> acc = new LinkedHashSet<>(options);
acc.add("-Dio.netty.allocator.maxOrder=11");
return acc;
}

View file

@ -151,6 +151,26 @@ public class JvmOptionsParserTest {
}
@Test
public void testEnvironmentOPTSVariableTakesPrecedenceOverOptionsFile() throws IOException {
String regex = "Xmx[^ ]+";
String expected = "Xmx25g";
File optionsFile = writeIntoTempOptionsFile(writer -> writer.println("-Xmx1g"));
JvmOptionsParser.handleJvmOptions(new String[] {"/path/to/ls_home", optionsFile.toString()}, expected);
final String output = outputStreamCaptor.toString();
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regex);
String lastMatch = pattern.matcher(output)
.results()
.map(java.util.regex.MatchResult::group)
.reduce((first, second) -> second)
.orElse(null);
assertEquals("LS_JAVA_OPTS env must take precedence over jvm.options file", expected, lastMatch);
}
private File writeIntoTempOptionsFile(Consumer<PrintWriter> writer) throws IOException {
File optionsFile = temp.newFile("jvm.options");
PrintWriter optionsWriter = new PrintWriter(new FileWriter(optionsFile));