Skip to content

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