Skip to content

Close Files.lines stream #14379

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

Merged
merged 2 commits into from
Jan 28, 2022
Merged

Close Files.lines stream #14379

merged 2 commits into from
Jan 28, 2022

Conversation

nicolasstucki
Copy link
Contributor

Fixes #14376

@nicolasstucki
Copy link
Contributor Author

Tested locally a few times without hitting the issue in #14376.

Comment on lines 50 to 54
files.flatMap(path => toolArgsParse {
val stream = Files.lines(path, charset)
try stream.limit(10).toScala(List)
finally stream.close()
})
Copy link
Member

Choose a reason for hiding this comment

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

We normally use scala.util.Using for this:

Suggested change
files.flatMap(path => toolArgsParse {
val stream = Files.lines(path, charset)
try stream.limit(10).toScala(List)
finally stream.close()
})
files.flatMap(path => toolArgsParse(Using(Files.lines(path, charset))(_.limit(10).toScala(List))))

Copy link
Member

@dwijnand dwijnand left a comment

Choose a reason for hiding this comment

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

I assumed "toScala(List)" were just as much as "terminal operation" as toArray is on j.u.s.Stream. Almost feel like it's a bug that it isn't.

Sorry for the bug.

@dwijnand dwijnand enabled auto-merge January 28, 2022 16:30
@dwijnand
Copy link
Member

Oh, nvm, terminal doesn't mean close apparently. https://stackoverflow.com/a/27382060/463761

@dwijnand dwijnand merged commit 593498d into scala:master Jan 28, 2022
@dwijnand dwijnand deleted the fix-#14376 branch January 28, 2022 17:06
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.

Vulpix leaks file handles
3 participants