Skip to content

fix(loader): stream temp dir during cleanup to avoid OOM - #322

Open
arimu1 wants to merge 1 commit into
fusesource:masterfrom
arimu1:fix/300-cleanup-tmp-oom
Open

fix(loader): stream temp dir during cleanup to avoid OOM#322
arimu1 wants to merge 1 commit into
fusesource:masterfrom
arimu1:fix/300-cleanup-tmp-oom

Conversation

@arimu1

@arimu1 arimu1 commented Aug 25, 2026

Copy link
Copy Markdown

Summary

  • Replace File.listFiles(FilenameFilter) in JansiLoader.cleanup() with Files.newDirectoryStream and a prefix filter for jansi-{version}-* entries.
  • File.listFiles internally calls File.list(), which materializes every name in /tmp into a String[] before the filter runs — this causes OutOfMemoryError when /tmp holds 250k+ unrelated entries (reported in JansiLoader.cleanup() throws OutOfMemory error if /tmp/ has 250,000+ directories #300 with -Xmx16m).
  • Files.newDirectoryStream applies the filter while iterating directory entries, so only matching jansi-* files are visited and unrelated temp entries are never loaded into heap.
  • Add a unit test that seeds 1000 unrelated temp files plus stale/locked jansi libs and verifies cleanup behavior without needing a massive temp directory.

Fixes #300

Test plan

  • mvn test -Dtest=JansiLoaderTest (Java 21)
  • New test cleanupDeletesStaleJansiLibsWithoutListingAllTempEntries passes: stale lib removed, locked lib kept, 1000 decoy files untouched

File.listFiles(FilenameFilter) materializes every /tmp entry before
filtering, which can exhaust heap when hundreds of thousands of unrelated
directories exist. Use Files.newDirectoryStream with a jansi-* prefix
filter so only matching entries are visited.

Fixes fusesource#300
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.

JansiLoader.cleanup() throws OutOfMemory error if /tmp/ has 250,000+ directories

1 participant