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

Prune fails: too many files open #3752

Open
nistath opened this issue Aug 1, 2019 · 17 comments · May be fixed by #3842
Open

Prune fails: too many files open #3752

nistath opened this issue Aug 1, 2019 · 17 comments · May be fixed by #3842
Labels

Comments

@nistath
Copy link

nistath commented Aug 1, 2019

Running git lfs prune on a large repository fails. This is on Ubuntu 16.04.
Here is the log.

Versions:
git-lfs/2.7.2 (GitHub; linux amd64; go 1.12.4)
git version 2.7.4

@bk2204
Copy link
Member

bk2204 commented Aug 2, 2019

Hey,

Can you provide the output of running ulimit -a and the number of CPU cores you have? We try to limit the number of processes we use (and therefore the number of pipes) based on the CPU cores, but for small values of RLIMIT_NOFILE, we may still use too many.

Also, we fixed at least one issue with file descriptor leaks in 2.8.0, so trying that version may help as well.

@optix2000
Copy link

Running into same issue on git-lfs/2.8.0 (GitHub; darwin amd64; go 1.12.7).

Logs:

git-lfs/2.8.0 (GitHub; darwin amd64; go 1.12.7)
git version 2.22.1

$ git-lfs prune
Prune error: open /Users/<snip>/.git/objects/pack/pack-48c6fa5c951d0f5ab51d9dd5179de7c5ef5e5922.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-48c6fa5c951d0f5ab51d9dd5179de7c5ef5e5922.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-301e05fb7ed276521d5ea41a7a37f4d2a2274064.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-48c6fa5c951d0f5ab51d9dd5179de7c5ef5e5922.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-301e05fb7ed276521d5ea41a7a37f4d2a2274064.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-31ec5118296824caceaaa81e964a465c240a01b4.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
...
pipe: too many open files

ENV:
LocalWorkingDir=/Users/<snip>
LocalGitDir=/Users/<snip>/.git
LocalGitStorageDir=/Users/<snip>/.git
LocalMediaDir=/Users/<snip>/.git/lfs/objects
LocalReferenceDirs=
TempDir=/Users/<snip>/.git/lfs/tmp
ConcurrentTransfers=3
TusTransfers=false
BasicTransfersOnly=false
SkipDownloadErrors=false
FetchRecentAlways=false
FetchRecentRefsDays=7
FetchRecentCommitsDays=0
FetchRecentRefsIncludeRemotes=true
PruneOffsetDays=3
PruneVerifyRemoteAlways=false
PruneRemoteName=origin
LfsStorageDir=/Users/<snip>/.git/lfs
AccessDownload=none
AccessUpload=none
DownloadTransfers=basic
UploadTransfers=basic
GIT_EXEC_PATH=/usr/local/Cellar/git/2.22.1/libexec/git-core

Client IP addresses:
<snip>
% ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       1418
-n: file descriptors                256

fd limit of 256, while low, is the default on MacOS. Ubuntu default IIRC is 1024.

Might be related to #2694 as our repo is quite large (136k commits, 27GB on disk)

@bk2204
Copy link
Member

bk2204 commented Aug 19, 2019

Okay, it's helpful to know that 256 is the default on macOS. I think we'll probably need to bump down the number of processes we use. I probably haven't noticed because my shell configuration unlimits everything it can.

I'll flag this accordingly.

@bk2204 bk2204 added the bug label Aug 19, 2019
@bk2204 bk2204 linked a pull request Sep 30, 2019 that will close this issue
@bk2204
Copy link
Member

bk2204 commented Sep 30, 2019

I have a draft PR in #3842 that should fix this. Could you possibly test with that branch and see if it fixes the issue for you? If not, I can adjust the heuristic.

@optix2000
Copy link

@bk2204 Unfortunately no-go.

git-lfs/2.8.0 (GitHub; darwin amd64; go 1.13.1; git b7e6a5e5)
git version 2.23.0

$ git-lfs prune
Prune error: open /Users/<snip>/.git/objects/pack/pack-3d3b1696daf0c2f14c61a962c6dc9288e73ca0dc.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-54a631bdb3f7e263b700fa68fb5f016d145f78c8.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-7e5bf6ac5074886fa641679c0ded7c785887b1bc.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-e2d8001a5abfd3853bcdcfa7847334d9fbf62729.pack: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: missing object: b70f4152b759a6c39a2e8ada517452658694123a
Prune error: open /Users/<snip>/.git/objects/9b/c30ad7406ea3a425001e64591a754c589a2026: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-294f8047f5317c222659fbe2c3bb9c534fc54ec1.pack: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-682dc7cb3e1eb7645e4905c59e2c97860acb6cba.pack: too many open files
Prune error: pipe: too many open files
Prune error: Failed to call git rev-parse --git-dir: pipe: too many open files 
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-3eddfd5b8f4781038be3f7890641b58d35d68cfd.pack: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-1808d0b766f856fa120bc1fd37c8967411ee81d7.pack: too many open files
Prune error: Failed to call git rev-parse --git-dir: pipe: too many open files 
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-1d53846ffbc4b5efdf7e00b792842b0d0fa59f1f.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-1808d0b766f856fa120bc1fd37c8967411ee81d7.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: fork/exec /usr/local/bin/git: bad file descriptor
Prune error: open /Users/<snip>/.git/objects/pack/pack-03633937e0ba19947e42770ce7cb643eb5e80210.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-3d3b1696daf0c2f14c61a962c6dc9288e73ca0dc.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-03633937e0ba19947e42770ce7cb643eb5e80210.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-472835eff418e3f92734513c7fd836c69fcb3b2f.pack: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-1808d0b766f856fa120bc1fd37c8967411ee81d7.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-1b79819fa7bafeac0c70045f1c25ad6994a8a92f.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-53b12d7d875d34f96a15291026d5d0b2275ba9b2.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-ed5cc0fe708a7c337aba68e5eafac1a12da96bd1.pack: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-e0e8cb0107399c64a861c6f81d536f51f175ddbf.pack: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: pipe: too many open files
Prune error: open /Users/<snip>/.git/objects/b7/0f4152b759a6c39a2e8ada517452658694123a: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-c3acb3c2f3a5154d680ffa1b133d11b1cce31437.pack: too many open files
Prune error: open /Users/<snip>/.git/objects/pack/pack-e2d8001a5abfd3853bcdcfa7847334d9fbf62729.pack: too many open files

open /Users/<snip>/.git/objects/pack/pack-e2d8001a5abfd3853bcdcfa7847334d9fbf62729.pack: too many open files

Current time in UTC: 
2019-10-09 00:36:29

ENV:
LocalWorkingDir=/Users/<snip>
LocalGitDir=/Users/<snip>/.git
LocalGitStorageDir=/Users/<snip>/.git
LocalMediaDir=/Users/<snip>/.git/lfs/objects
LocalReferenceDirs=
TempDir=/Users/<snip>/.git/lfs/tmp
ConcurrentTransfers=3
TusTransfers=false
BasicTransfersOnly=false
SkipDownloadErrors=false
FetchRecentAlways=false
FetchRecentRefsDays=7
FetchRecentCommitsDays=0
FetchRecentRefsIncludeRemotes=true
PruneOffsetDays=3
PruneVerifyRemoteAlways=false
PruneRemoteName=origin
LfsStorageDir=/Users/<snip>/.git/lfs
AccessDownload=none
AccessUpload=none
DownloadTransfers=basic,lfs-standalone-file
UploadTransfers=basic,lfs-standalone-file

Client IP addresses:
<snip>

@optix2000
Copy link

What looks like is happening is the underlying git commands are each opening ~64 FD's themselves. Probably need to set the calculation to assume that each command uses 64 FD's (or more) to be more conservative.

@bk2204
Copy link
Member

bk2204 commented Oct 9, 2019

Can you try again with the version I've just pushed up which makes that change?

@optix2000
Copy link

I stuck in some prints to validate how many threads it would limit it to.

git-lfs prune
256
3
Prune error: open /Users/<snip>/.git/objects/pack/pack-d940095e45e18e42e2aaa2f1e5756fc037b82bdb.pack: too many open files

Despite it supposedly using only 3 threads, there are still dozens of git processes.

% ps ax | grep git | wc -l
      60

Consisting of multiples of these commands:

git -c filter.lfs.smudge= -c filter.lfs.clean= -c filter.lfs.process= -c filter.lfs.required=false cat-file --batch-check
git -c filter.lfs.smudge= -c filter.lfs.clean= -c filter.lfs.process= -c filter.lfs.required=false rev-list --stdin --objects --no-walk --

And one of these:

git -c filter.lfs.smudge= -c filter.lfs.clean= -c filter.lfs.process= -c filter.lfs.required=false log --branches --tags --not --remotes=origin -G oid sha256: -p -U12 --format=lfs-commit-sha: %H %P

@ravenAtSafe
Copy link

Just to make the implied workaround explicit, running ulimit -n 2048 before pruning worked for me (also a fairly large repo).

git: 2.20.1
git-lfs: 2.7.2

@jspiro
Copy link

jspiro commented Jun 15, 2020

I hit this as well and setting a high ulimit helped. 8 core 16" 2019 MBP.

@rickheil
Copy link

I am also still seeing this behavior, and ulimit seems to have worked around it. If any additional logs would help debug, just let me know and I'm happy to provide.

@MaxwellDexter
Copy link

Also received this bug on macOS High Sierra, 2015 MBP. ulimit works for me as well.
Run ulimit -n 1024 to set the number of of open files allowed to 1024

@kalkwarf
Copy link

I ran into this problem yesterday on a Mac running Monterey (12.3.1). No amount of fussing with ulimit had any effect.

I started poking around in the prune code, and noticed

sem := semaphore.NewWeighted(int64(runtime.NumCPU() * 2))

Removing the multiplier, and using

sem := semaphore.NewWeighted(int64(runtime.NumCPU()))

was enough to allow the prune to succeed. Obviously, this is a pretty crude "fix" and probably isn't reliable for every case.

I guess I need to find where all the descriptors went. Are we failing to close files after we look at them, or is this merely an artifact of all the subprocesses being spawned?

@whitty
Copy link

whitty commented Jun 30, 2023

Ran into this issue on ubuntu 20.04 (ulimit is 1024 - cannot be increased by normal user).

Workaround was to use taskset to restrict the CPU set to convince runtime.NumCPU() to be lower.

taskset 1 git lfs prune

@aaronborden-rivian
Copy link

aaronborden-rivian commented Jan 26, 2024

According to this stackoverflow post, NumCPU will return the number of system cores, which will be too high when running in a container with only a subset of CPUs.

Can the concurrency be exposed via a config option so that we can overwrite it at runtime based on the container size? This is true for other operations as well, but I'll open a separate issue for that.

@bk2204
Copy link
Member

bk2204 commented Jan 29, 2024

Can the concurrency be exposed via a config option so that we can overwrite it at runtime based on the container size? This is true for other operations as well, but I'll open a separate issue for that.

We'd certainly accept a patch to that effect. It's possible we'll get to it without that, but given the difficulty of reproducing this problem in order to fix it, I think someone who's actually experiencing the problem would be best suited to do so.

@bk2204
Copy link
Member

bk2204 commented Jan 29, 2024

I should also note that the number of CPUs is actually a heuristic since we don't know how many file descriptors will be opened, so it doesn't really matter what the number of available cores actually is. As a result, it's not necessarily super useful to adjust the number of cores, but rather we should implement a more robust solution, which nobody has suggested yet (and, because I cannot reproduce the problem repeatedly, I cannot implement).

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

Successfully merging a pull request may close this issue.

10 participants