Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent file handle leak during individual purge #707

Merged

Conversation

bbpennel
Copy link
Contributor

#706

Use a try-with-resource block when getting the stream of files in derivative directory to avoid file handle leak

try {
return Files.list(cachePath)
try (final var fileStream = Files.list(cachePath)) {
return fileStream
.filter(p -> p.getFileName().toString().startsWith(expectedNamePrefix))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbpennel. Nice! so the try() will auto close the fileStream... But... is the filter needed? Given the way caches are structured all files inside cachePath will need to be returned. Maybe for sanity just check if the file is regular file?
.filter(Files::isRegularFile) or something like that? I mean, just to save a few milliseconds per cycle... specially on large images with tons of derivatives

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter isn't a change in this PR, i didn't really evaluate whether it was needed or not. I'm fine with removing it if there isn't any concern of the cache path containing files that don't begin with the md5.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbpennel thanks, true!, for the sake of not adding any point of rupture and because I don't know what use case the original Developer might had had in place, let's keep it! Approving. Thanks!

@glenrobson
Copy link
Contributor

Cantaloupe group met and like this fix. If you can respond to the filter question reaised above then we can look at merging.

@DiegoPino DiegoPino added this to the 6.0 milestone Nov 6, 2024
@DiegoPino
Copy link
Contributor

@bbpennel there is a test failing (looks related... but might be yet again a transient/timeout error on writing a file/reading it)
JdbcCacheTest>AbstractCacheTest.testPurgeInfos:469->AbstractCacheTest.assertExists:36 expected: not
So will re-run this test if that is the case

@DiegoPino DiegoPino merged commit 0dccf29 into cantaloupe-project:develop Nov 6, 2024
8 checks passed
@bbpennel bbpennel deleted the fix-cache-purge-leak-develop branch November 6, 2024 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants