mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Fix Gradle File leaks (#105597)
Fixing a couple of file leaks (and cleaning up one missing try-with-resources). The directory descriptor leaks in particular were leaking massively on every precommit run, to the point where it slows down the whole system and/or we're running into descriptor limits.
This commit is contained in:
parent
6fec837e32
commit
3f8bc36788
4 changed files with 13 additions and 9 deletions
|
@ -21,11 +21,8 @@ import java.util.Properties;
|
||||||
public class VersionPropertiesLoader {
|
public class VersionPropertiesLoader {
|
||||||
static Properties loadBuildSrcVersion(File input, ProviderFactory providerFactory) throws IOException {
|
static Properties loadBuildSrcVersion(File input, ProviderFactory providerFactory) throws IOException {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
InputStream is = new FileInputStream(input);
|
try (InputStream is = new FileInputStream(input)) {
|
||||||
try {
|
|
||||||
props.load(is);
|
props.load(is);
|
||||||
} finally {
|
|
||||||
is.close();
|
|
||||||
}
|
}
|
||||||
loadBuildSrcVersion(props, providerFactory);
|
loadBuildSrcVersion(props, providerFactory);
|
||||||
return props;
|
return props;
|
||||||
|
|
|
@ -146,13 +146,16 @@ public class CopyRestApiTask extends DefaultTask {
|
||||||
try {
|
try {
|
||||||
// check source folder for tests
|
// check source folder for tests
|
||||||
if (sourceResourceDir != null && new File(sourceResourceDir, REST_TEST_PREFIX).exists()) {
|
if (sourceResourceDir != null && new File(sourceResourceDir, REST_TEST_PREFIX).exists()) {
|
||||||
return Files.walk(sourceResourceDir.toPath().resolve(REST_TEST_PREFIX))
|
try (var files = Files.walk(sourceResourceDir.toPath().resolve(REST_TEST_PREFIX))) {
|
||||||
.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
|
return files.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// check output for cases where tests are copied programmatically
|
// check output for cases where tests are copied programmatically
|
||||||
File yamlTestOutputDir = new File(additionalYamlTestsDir.get().getAsFile(), REST_TEST_PREFIX);
|
File yamlTestOutputDir = new File(additionalYamlTestsDir.get().getAsFile(), REST_TEST_PREFIX);
|
||||||
if (yamlTestOutputDir.exists()) {
|
if (yamlTestOutputDir.exists()) {
|
||||||
return Files.walk(yamlTestOutputDir.toPath()).anyMatch(p -> p.getFileName().toString().endsWith("yml"));
|
try (var files = Files.walk(yamlTestOutputDir.toPath())) {
|
||||||
|
return files.anyMatch(p -> p.getFileName().toString().endsWith("yml"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException(String.format("Error determining if this project [%s] has rest tests.", getProject()), e);
|
throw new IllegalStateException(String.format("Error determining if this project [%s] has rest tests.", getProject()), e);
|
||||||
|
|
|
@ -118,7 +118,9 @@ public abstract class LoggedExec extends DefaultTask implements FileSystemOperat
|
||||||
try {
|
try {
|
||||||
// the file may not exist if the command never output anything
|
// the file may not exist if the command never output anything
|
||||||
if (Files.exists(spoolFile.toPath())) {
|
if (Files.exists(spoolFile.toPath())) {
|
||||||
Files.lines(spoolFile.toPath()).forEach(logger::error);
|
try (var lines = Files.lines(spoolFile.toPath())) {
|
||||||
|
lines.forEach(logger::error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("could not log", e);
|
throw new RuntimeException("could not log", e);
|
||||||
|
|
|
@ -458,7 +458,9 @@ public class ElasticsearchNode implements TestClusterConfiguration {
|
||||||
// make sure we always start fresh
|
// make sure we always start fresh
|
||||||
if (Files.exists(workingDir)) {
|
if (Files.exists(workingDir)) {
|
||||||
if (preserveDataDir) {
|
if (preserveDataDir) {
|
||||||
Files.list(workingDir).filter(path -> path.equals(confPathData) == false).forEach(this::uncheckedDeleteWithRetry);
|
try (var files = Files.list(workingDir)) {
|
||||||
|
files.filter(path -> path.equals(confPathData) == false).forEach(this::uncheckedDeleteWithRetry);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
deleteWithRetry(workingDir);
|
deleteWithRetry(workingDir);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue