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

Bugfix/65 close memory mapped buffer #66

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/riscure/trs/TraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ private void checkValid(Trace trace) {
}

private void closeReader() throws IOException {
buffer = null;
readStream.close();
}

Expand Down
21 changes: 21 additions & 0 deletions src/test/java/TestTraceSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,25 @@ void test61ReadLegacyTraceWithoutData() throws IOException, TRSFormatException {
assertDoesNotThrow(() -> ts.get(0));
}
}

/**
* Test to reproduce Github issue #65: TRS files remain 'in use' after they have been closed
* Test this issue by opening and closing a file, and then checking whether the file can be deleted.
*/
@Test
void testFileReleasing() throws IOException, TRSFormatException, InterruptedException {
String filePath = tempDir.toAbsolutePath() + File.separator + BYTES_TRS;
// Open the file, and let the try-with-resources statement close it
try (TraceSet traceSet = TraceSet.open(filePath)) {
traceSet.getMetaData().getTraceSetParameters();
}
// Unfortunately, the current solution requires a garbage collect to have been performed before the issue is resolved.
// Other fixes required either a Java 8 Cleaner.clean() call not accessible from Java 21, or a Java 20 Arena.close(),
// which is not been finalized in Java 21.
System.gc();
Thread.sleep(1000);
// Assert that the opened file has been closed again, by deleting it.
File file = new File(filePath);
assert(file.delete());
}
}
Loading