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

dir.list.filter().toList does not close the directory file descriptor #283

Closed
bchazalet opened this issue Dec 13, 2018 · 2 comments
Closed
Labels

Comments

@bchazalet
Copy link

bchazalet commented Dec 13, 2018

I kept getting a "too many files open" exception in my program which processes a large number of files and scans a large number of directories. After investigating I found out that my number of file descriptors kept forever increasing. The problem is with the way I listed directories, namely:

val jsonOnDisk = jsonDir
  .list
  .filter(f => f.isRegularFile && (f.extension == Some(".json") || f.extension(includeAll = true) == Some(".json.gz")))
  .toList

Doing so, the jsonDir file descriptor is kept open forever. I use lsof -p <pid> | egrep 'DIR|REG' to see the open file descriptors for my process.

I found that doing this solves my problem:

val jsonOnDisk = jsonDir
  .list(f => f.isRegularFile && (f.extension == Some(".json") || f.extension(includeAll = true) == Some(".json.gz")))
  .toList

I am not sure this is a bug, one could say I was not using the library the right way, but I'll let you decide.

@bchazalet bchazalet changed the title dir.list.filter().toList does not close the directory file descriptor dir.list.filter().toList does not close the directory file descriptor Dec 13, 2018
@pathikrit pathikrit added the bug label Feb 24, 2019
@pathikrit
Copy link
Owner

Yes, the issue is java.nio.file.Files.list which better-file relies on returns a java.util.stream.Stream which needs to be closed.

@bchazalet
Copy link
Author

Thank you @pathikrit !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants