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

Master SharedFileInputStream closes unexpectedly #694

Closed
SeongEon-Jo opened this issue Jul 22, 2023 · 0 comments · Fixed by #695
Closed

Master SharedFileInputStream closes unexpectedly #694

SeongEon-Jo opened this issue Jul 22, 2023 · 0 comments · Fixed by #695
Assignees

Comments

@SeongEon-Jo
Copy link
Contributor

Describe the bug
Master SharedFileInputStream closes unexpectedly after GC even if some slave SharedFileInputStream(constructed by newStream()) are still being referenced.

Detailed exception is IOException: Stream Closed

To Reproduce
Steps to reproduce the behavior:

Here's a simple failing test case to reproduce the error.

@Test
void test() throws Exception {
    // you can use any file to test
    File file = Paths.get("src/test/resources/test_file.jpeg").toFile();
   
    InputStream slaveSharedFileIs = new SharedFileInputStream(file).newStream(0, -1);
   
    System.gc();

    Assertions.assertDoesNotThrow(() -> slaveSharedFileIs.read());
}

I guess master SharedFileInputStream which is not referenced anymore calls finalize() and close() when GC works, so slave SharedFileInputStream also cannot access the file after that.

To prove, the test case below succeeds.

@Test
void test() throws Exception {
    // you can use any file to test
    File file = Paths.get("src/test/resources/test_file.jpeg").toFile();

    SharedFileInputStream masterSharedFileIs = new SharedFileInputStream(file);
    
    InputStream slaveSharedFileIs = masterSharedFileIs.newStream(0, -1);
   
    System.gc();

    Assertions.assertDoesNotThrow(() -> slaveSharedFileIs.read());
}

Expected behavior
RandomAccessFile should not be closed when there is at least one of remaining SharedFileInputStream still being referenced(used)

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 a pull request may close this issue.

2 participants