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

Too many open files with cabal new-sdist and many data-files #5541

Closed
nomeata opened this issue Aug 23, 2018 · 8 comments · Fixed by #5558
Closed

Too many open files with cabal new-sdist and many data-files #5541

nomeata opened this issue Aug 23, 2018 · 8 comments · Fixed by #5558
Milestone

Comments

@nomeata
Copy link
Contributor

nomeata commented Aug 23, 2018

A project that I was trying to build contains one package (ghc-toolkit) that has 1054 files in data-files defined
(https://github.com/tweag/asterius/tree/caf15690c54aef3ae4eecbc7224c6163de040f7a/ghc-toolkit).

It also contains another package genapply that does not even depend on ghc-toolkit.

I can run cabal new-build genapply just fine. But if I run cabal new-install genapply, I get

$ cabal new-install genapply -w ~/build/haskell/ghc/inplace/bin/ghc-stage2 --allow-newer=base
Wrote tarball sdist to
/home/jojo/build/haskell/asterius/dist-newstyle/sdist/asterius-0.0.1.tar.gz
boot-libs/template-haskell/Language/Haskell/TH/LanguageExtensions.hs: openBinaryFile: resource exhausted (Too many open files)

Interestingly,

$ cabal new-sdist genapply 
Downloading
https://github.com/haskell/primitive/archive/ea9f0426646ecf8a5a0a1659b29a8dc014ceda05.tar.gz
Wrote tarball sdist to
/home/jojo/build/haskell/asterius/dist-newstyle/sdist/genapply-0.1.tar.gz

works, but

$ cabal new-sdist all
Downloading
https://github.com/haskell/primitive/archive/ea9f0426646ecf8a5a0a1659b29a8dc014ceda05.tar.gz
Wrote tarball sdist to
/home/jojo/build/haskell/asterius/dist-newstyle/sdist/asterius-0.0.1.tar.gz
boot-libs/template-haskell/Language/Haskell/TH/Ppr.hs: openBinaryFile: resource exhausted (Too many open files)

does not.

So maybe there are two issues here:

  • cabal new-install creates more sdists than it has to.
  • cabal new-sdist does not work well with large number of data-files.
@nomeata nomeata changed the title Too many open files Too many open files with cabal new-sdist and many data-files Aug 23, 2018
@hvr hvr added the type: bug label Aug 23, 2018
@hvr
Copy link
Member

hvr commented Aug 23, 2018

It's quite possible new-sdist might have uncovered a long-standing bug in the sdist code...

nomeata added a commit to nomeata/cabal that referenced this issue Aug 23, 2018
@typedrat
Copy link
Collaborator

This means files aren't getting closed correctly, because if new-sdist works for one it should work for all.

nomeata added a commit to nomeata/cabal that referenced this issue Aug 23, 2018
@typedrat
Copy link
Collaborator

typedrat commented Sep 1, 2018

I've been looking at the code and thinking about this for the last bit, and I just do not see how this bug is possible.

I can see two options:

  1. listPackageSources or something in its call tree is leaking file handles
  2. Somehow, BSL.readFile is leaking file handles, because that's the only thing that actually deals with the file system for each file in the sdist in CmdSdist.hs

Neither of these seems particularly plausible, but there has to be something going on.

@23Skidoo
Copy link
Member

23Skidoo commented Sep 1, 2018

Lazy I/O? A missing bracket leading to a resource leak?

@typedrat
Copy link
Collaborator

typedrat commented Sep 1, 2018

I don't see any obvious resource acquisitions, so I'm pretty close to saying (through the process of elimination) it's (curses!) lazy IO.

@typedrat
Copy link
Collaborator

typedrat commented Sep 1, 2018

Read an entire file lazily into a ByteString. The Handle will be held open until EOF is encountered.

So I need to slurp the whole file into memory and then convert that strict BS into a lazy BS, I guess.

typedrat added a commit to typedrat/cabal that referenced this issue Sep 1, 2018
@typedrat typedrat mentioned this issue Sep 1, 2018
typedrat added a commit to typedrat/cabal that referenced this issue Sep 1, 2018
@hvr hvr added this to the 2.4 milestone Sep 2, 2018
@hvr
Copy link
Member

hvr commented Sep 2, 2018

NB: this was already cherry-picked to 2.4

@nomeata
Copy link
Contributor Author

nomeata commented Sep 2, 2018

Thanks!

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

Successfully merging a pull request may close this issue.

4 participants