Skip to content

Commit cc5d9ac

Browse files
authored
Fix file descriptors leak (#884)
1 parent 42887dd commit cc5d9ac

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

server/src/main/java/com/defold/extender/services/DefoldSdkService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.CompletableFuture;
4343
import java.util.concurrent.ConcurrentHashMap;
4444
import java.util.concurrent.ExecutionException;
45+
import java.util.stream.Stream;
4546

4647
@Service
4748
public class DefoldSdkService {
@@ -294,9 +295,8 @@ public void destroy() {
294295
return;
295296
}
296297
LOGGER.info("Cleaning up SDK cache");
297-
try {
298-
Files.list(configuration.getLocation())
299-
.filter(path -> ! path.endsWith(TEST_SDK_DIRECTORY))
298+
try (Stream<Path> entries = Files.list(configuration.getLocation())) {
299+
entries.filter(path -> ! path.endsWith(TEST_SDK_DIRECTORY))
300300
.forEach(this::deleteCachedSdk);
301301
} catch(IOException e) {
302302
LOGGER.warn("Failed to list SDK cache directory: " + e.getMessage());

server/src/test/java/com/defold/extender/services/DefoldSDKServiceTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.ExecutorService;
2020
import java.util.concurrent.Executors;
2121
import java.util.stream.Collectors;
22+
import java.util.stream.Stream;
2223

2324
import org.apache.commons.io.FileUtils;
2425
import org.json.simple.parser.ParseException;
@@ -161,7 +162,10 @@ public void onlyStoreTheNewest() throws IOException, ExtenderException {
161162
defoldSdkService.getSdk(sdkHash);
162163
}
163164

164-
List<String> collect = Files.list(DefoldSDKServiceTest.configuration.getLocation()).map(path -> path.toFile().getName()).collect(Collectors.toList());
165+
List<String> collect = null;
166+
try (Stream<Path> entries = Files.list(DefoldSDKServiceTest.configuration.getLocation())) {
167+
collect = entries.map(path -> path.toFile().getName()).collect(Collectors.toList());
168+
}
165169

166170
assertEquals(DefoldSDKServiceTest.configuration.getCacheSize(), collect.size());
167171
assertTrue(collect.contains("e41438cca6cc1550d4a0131b8fc3858c2a4097f1"));

server/src/test/java/com/defold/extender/services/cocoapods/ResolvedPodsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
14+
import java.util.stream.Stream;
1415

1516
import javax.naming.InvalidNameException;
1617

@@ -125,7 +126,10 @@ public void testResourceBundleParsing() throws IOException, ExtenderException {
125126

126127
File bundleDir = new File(targetDir, "UnityAdsResources.bundle");
127128
assertTrue(bundleDir.exists());
128-
List<Path> resultContent = Files.list(bundleDir.toPath()).toList();
129+
List<Path> resultContent = null;
130+
try (Stream<Path> entries = Files.list(bundleDir.toPath())) {
131+
resultContent = entries.toList();
132+
}
129133
assertEquals(expectedFiles.size(), resultContent.size());
130134
for (Path p : resultContent) {
131135
assertTrue(expectedFiles.contains(p.getFileName().toString()));

0 commit comments

Comments
 (0)