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

File descriptor leak in Nix master #4046

Closed
thufschmitt opened this issue Sep 21, 2020 · 10 comments
Closed

File descriptor leak in Nix master #4046

thufschmitt opened this issue Sep 21, 2020 · 10 comments
Labels

Comments

@thufschmitt
Copy link
Member

Describe the bug

Building a derivation with Nix master leaves a number of file descriptors that aren't closed until Nix exits

Steps To Reproduce

  1. In the background, monitor the number of FDs used by a nix-build process (replace by nix-store if you're using the daemon)

    $ while true; do lsof -c nix-build | wc -l; done
  2. Build a big-enough number of independant derivations:

    $ nix-build many-drvs.nix

    where many-drvs.nix is as follows:

    let pkgs = import <nixpkgs> {}; in
    
    builtins.map
      (i: pkgs.writeText "foo" (toString builtins.currentTime + toString i))
      (pkgs.lib.genList (i: i) 1000)

    watch the output of lsof grow (up to ~5000 in my tests).

Expected behavior

The number of opened file descriptors should be bounded (it stays under 100 for nix 2.3.7)

nix-env --version output

$ nix-env --version
nix-env (Nix) 3.0pre20200829_f156513

Additional context

Looking at the lsof output, I see a lot of .lock (~half of the output) and .drv.bz2 (~1/4th of the output) files. I guess we forget to release these at some point

@stale
Copy link

stale bot commented Mar 21, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Mar 21, 2021
@cole-h
Copy link
Member

cole-h commented Mar 22, 2021

I just tried this on nix-env (Nix) 2.4pre20210308_1c0e3e4 and it stayed at about 58 the entire time. It seems like this was resolved in some intermediate commit?

@stale stale bot removed the stale label Mar 22, 2021
@edolstra
Copy link
Member

edolstra commented Apr 7, 2021

Yeah, I can't reproduce this. Top-level substitution goals had a similar FD leak (8a29052).

@edolstra edolstra closed this as completed Apr 7, 2021
@veprbl
Copy link
Member

veprbl commented Apr 4, 2022

Still reproducible on 2.7.0

@thufschmitt
Copy link
Member Author

@veprbl how did you manage to reproduce it? Just tried on 2.8.0pre20220317_a0b517d, but the FD count stayed nicely bounded

@veprbl
Copy link
Member

veprbl commented Apr 6, 2022

Just evaluated texlive from master on macOS and observed "Too many open files" on Nix 2.7.0. Trying on 2.3.16 fixed the issue.

@thufschmitt
Copy link
Member Author

Oh it’s happening at eval-time? Interesting…

Still can’t reproduce though. Maybe it’s a darwin-specific thing ? 🤔

@veprbl
Copy link
Member

veprbl commented Apr 6, 2022

I meant build. I remember originally I also saw a similar behaviour on Linux, it was opening some extra files (not the .lock's) in the store.

@tobiasBora
Copy link

tobiasBora commented May 2, 2022

I can experience this again, on NixOs when installing texlive with the documentation NixOS/nixpkgs#171218

I can fix it by building first my system with

  security.pam.loginLimits = [{
    domain = "*";
    type = "soft";
    item = "nofile";
    value = "65535";
  }];

@aameen-tulip
Copy link
Contributor

This was causing issues for me building ( an admittingly large ) Yarn project on Debian 11 ( barebones cloud-init image with nothing other than nix installed ), Nix 2.7.0, multi-user.

Nix was trying to build ~6,000 derivations at once, so in fairness, it was a heavy load.

I tried several of the most common ways to raise the max file limit with little success; but what finally worked was overriding the limit in the service:

sudo systemctl edit nix-daemon.service;
# In your editor set these fields
[Service]
LimitNOFILE=65535
LimitNOFILESoft=65535

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

6 participants