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

Missing open/close from Files.lines #20

Closed
z669016 opened this issue Dec 21, 2014 · 4 comments · Fixed by #76
Closed

Missing open/close from Files.lines #20

z669016 opened this issue Dec 21, 2014 · 4 comments · Fixed by #76

Comments

@z669016
Copy link

z669016 commented Dec 21, 2014

Hi,
I tried to figure out if my Files.lines("some-path") stream is closed correctly. I used the agent but if I use the trace option, I do see messages from class files being opened and closed, but the text file ("some-path") is not in the list.
Are streams handled differently, or does the agent just doesn't see the calls for the open/close?

public static void main(String[] args) {
    Stream<Entry> entries = getEntries();
    entries.forEach(System.out::println);
    entries.close();
}

public static Stream<Entry> getEntries() {
    Path path = Paths.get("./src/test/resources", "entries.txt");
    try {
        Stream<String> lines = Files.lines(path);
        return lines.map(line -> asEntry(line));
    } catch (IOException exc) {
        System.out.println(exc);
    }

    return Stream.empty();
}

Regards,
René

@kohsuke
Copy link
Member

kohsuke commented Jan 28, 2015

Looks like the FileDescriptor sun.nio.fs.UnixChannelFactory.open(...) needs to be intercepted.

@binma1
Copy link

binma1 commented Jan 13, 2016

@z669016 I've had a similar problem that calling Files.lines too many times will cause a "too many opened files" exception. Perhaps there is indeed a file leak in Java's Files.lines()?

@centic9
Copy link
Member

centic9 commented Jan 13, 2016

@binma1 , you have to close the stream to free the file handle.

This issue is about adding support for finding such invalid uses via file-leak-detector.

@binma1
Copy link

binma1 commented Jan 13, 2016

@centic9 Thanks!

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.

4 participants