Repository navigation
Closed
Labels
Description
If I clone a large Git LFS repo (~1GB native Git objects + ~30GB LFS objects) like this:
git lfs clone https://server/org/repo.git
Then I can reliably reproduce the following error:
...
Git LFS: (6802 of 7093 files) 5.08 GB / 5.17 GB
trace git-lfs: HTTP: GET https://server/lfs/2188/objects/2f36b022c374238616fe05181082d0fa6d0000cbefff04d2219df2ad5bcc0f7c
Git LFS: (6803 of 7093 files) 5.08 GB / 5.17 GB
error: git-lfs died of signal 9
Setup
$ git --version
git version 2.13.2
$ git lfs version
git-lfs/2.2.1 (GitHub; darwin amd64; go 1.8.3)
$ git config -l | grep lfs
lfs.batch=true
lfs.concurrenttransfers=10
lfs.transfer.maxretries=10
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
Observations
- the error seems to happen only on macOS (I was not able to reproduce it on Windows so far)
- the error happens somewhat randomly (not for the same LFS files) but always after ~5GB
git lfs clonecalls internallygitwhich in turn calls internallygit lfs. I thinkgitprints the error message here. This is the output in the process view:
-+= 60783 lars git lfs clone https://server/org/repo.git
\-+- 60784 lars /usr/local/bin/git-lfs clone https://server/org/repo.git
|--- 61066 lars git ls-tree -r -l -z --full-tree cbea3229a0999e5da8777cf69605785745150100
|--- 61067 lars git cat-file --batch
\-+- 61080 lars git update-index -q --refresh --stdin
\--- 61081 lars git-lfs filter-process
- shortly before the process dies my machine completely freezes. My guess is that
git-lfsexcessively allocates system resources. I monitored the resource consumption withps auxand recorded the high CPU usage right before the process died:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
lars 13556 110.1 13.1 556753000 2194964 s007 R+ 11:32AM 12:04.69 /usr/local/bin/git-lfs clone https://server/org/repo.git
lars 13556 119.3 11.1 556753000 1869576 s007 R+ 11:32AM 12:06.00 /usr/local/bin/git-lfs clone https://server/org/repo.git
lars 13556 119.3 13.1 556753000 2198776 s007 R+ 11:32AM 12:07.28 /usr/local/bin/git-lfs clone https://server/org/repo.git
lars 13556 123.9 15.2 556753000 2556848 s007 R+ 11:32AM 12:08.60 /usr/local/bin/git-lfs clone https://server/org/repo.git
lars 13556 133.9 16.3 556753000 2726700 s007 R+ 11:32AM 12:09.97 /usr/local/bin/git-lfs clone https://server/org/repo.git
- if I set
lfs.concurrenttransfers=1andlfs.transfer.maxretries=0then I can still reliably reproduce the error - I was not able to reproduce the error with a fake repository so far
Do you have a clue what that error might be? How would you continue with the debugging? I think it would make sense to add additional debug output (I am already running it with GIT_TRACE=1 GIT_CURL_VERBOSE=1 GIT_TRACE_PACKET=1). Can you recommend good places for debug output?
Thanks,
Lars
Activity
ttaylorr commentedon Jul 25, 2017
@larsxschneider thanks for opening this. I think this has to do with the number of file descriptors that LFS has open at any one time. One approach that I tend to use when debugging problems like this:
or printing the
runtime.MemStatsperiodically while running LFS:larsxschneider commentedon Jul 26, 2017
@ttaylorr thanks for the hints!
The number of file descriptors seems not to be the issue as no more than 59 files are open at a time. However, the memory statistics are interesting (we have 2 git-lfs processed as explained above):
Git LFS process 1:
Git LFS process 2:
If I am reading this right then this means Git LFS allocates 96GB before it dies. Looks like a memory leak?!
larsxschneider commentedon Jul 26, 2017
FYI: @pluehne @terrorobe 👆
ttaylorr commentedon Jul 28, 2017
Are you looking at the
TotalAllocfield? If so, I don't think this is entirely correct. From the docs[1]:HeapAllocmay be a better indicator of what's "currently" going on inside of the LFS process.That all said, I don't see anything particular abnormal, other than LFS at some point during the process allocated a lot of memory (and then freed it). I would love to figure out where this is coming from, so I think it's time to start using
go tool pprof.Here's a diff to apply to LFS in order to generate a pprof report:
You can then run
go tool pprofwith that profile and examine the locations where the most heap memory is allocated.Keep in mind:
go tool pprofis known to have issues on macOS, so this is best run inside a Linux environment.See more: https://blog.golang.org/profiling-go-programs.
larsxschneider commentedon Jul 28, 2017
Please look closely at the output of Git LFS process 1. It shows 96GB heap alloc:
I will try to get more info with the
pproftool. Thank you 👍 🙂larsxschneider commentedon Aug 1, 2017
@ttaylorr : @pluehne and I patched the Git LFS binary according to your suggestion. We write the heap profile and exit if more than 1GB on the heap was allocated: pluehne@954c4e6
Here is the output of the pperf tool:
Unfortunately, there are only Golang core functions in the output. We did not manage Git LFS functions in there. Do you have any idea why?
There are plenty of places where we use
io.Copy(..):https://github.com/git-lfs/git-lfs/search?utf8=%E2%9C%93&q=%22io.Copy%28%22&type=
Do you have an idea which one it might be? Can you give us a hint how to debug this further?
Thanks!
ttaylorr commentedon Aug 1, 2017
@larsxschneider thanks! Can you try running
pprofwith the--alloc_spaceflag? That should show us all allocations since the program started, not just live allocations at the time of heap collection.For more: https://software.intel.com/en-us/blogs/2014/05/10/debugging-performance-issues-in-go-programs.
pluehne commentedon Aug 1, 2017
@ttaylorr I called
pprofwith--alloc_space, and indeed, the output is somewhat more detailed:Hope this helps!
ttaylorr commentedon Aug 1, 2017
@pluehne this is very helpful, I think I have an idea of what is going wrong. Can you apply the following diff and send me the output of stderr?
pluehne commentedon Aug 1, 2017
@ttaylorr Thanks, I will apply the patch tomorrow and post the
stderrhere :).pluehne commentedon Aug 2, 2017
@ttaylorr Here is the
stderroutput that I got with your patch applied.ttaylorr commentedon Aug 2, 2017
@pluehne hm, my thought was that the calls to
lfs.(*PointerScanner).next()were allocating large amounts of memory that was not freed, but this does not seem to be the case. I added up the total number of bytes read by that function that you linked above, and the total was rather small.Does the pprof generated with
--inuse_spaceappear the same as the original pprof graph you shared?--alloc_spaceshows us LFS functions, but the majority of these, I assume, are being freed correctly.--inuse_spacewould show us the profile at the time of heap collection, which would include unfreed memory on the heap. Hopefully one of those would be an LFS function that we could drill into further.larsxschneider commentedon Aug 3, 2017
@ttaylorr I just rerun the test on @pluehne 's Linux box and I replicated the issue:
1. inuse_space graph
2. alloc_space graph
rubyist commentedon Aug 4, 2017
I took a run at this with a handful of scenarios and couldn't reproduce, but if you're getting heap profiles showing memory leaks you can get a little more info from them with the
peekandlistfunctions. In the interactive sessionpeek makeSlicemight show you higher level things that are leading to that area. If that shows any git-lfs functions you canlist <func>to see a breakdown of which lines of code are doing the allocations.When looking at the final memstats outputs, it's worth comparing
MallocsandFrees, and possibly forcing a GC before taking the stats.Is there anything else particular to this repo that might help? What does the file size distribution look like [1]? Do you experience any network errors during this? Are any files symlinks? How much RAM do the machines have where this is happening?
When it happens on OSX is there anything in the console log? If the kernel kills something because it's consuming all the memory you'd see a line starting with something like
low swap: killing largest compressed process with pid ..., or scanning forgit-lfsmight turn up other reasons. If you're reproducing on linux you can checkdmesgfor similar kinds of messages.[1]
find . -type f -print0 | xargs -0 ls -l | awk '{size[int(log($5)/log(2))]++}END{for (i in size) printf("%10d %3d\n", 2^i, size[i])}' | sort -nlarsxschneider commentedon Aug 7, 2017
I've used the
peekandlistfunctions but I was not able to find source from thegit-lfspackage leaking. The leaking seems to start in the os/exec package (see output below).I can't think of anything that is special about this repo. I also was not able to generate a dummy repo to replicate the issues, too.
We are investigating network issues (see #2314) - this might be related.
No.
The Linux box has 12GB and the Mac 16GB RAM. We can reproduce it reliably on both systems.
I think it is correct that the kernel kills this process as it is allocating lots and lots of memory.
go pprof output
Is this useful to you?
larsxschneider commentedon Aug 7, 2017
I rerun the test and stopped the
git-lfsprocess after it allocated 4 GB of memory. Same result:ttaylorr commentedon Aug 7, 2017
@larsxschneider thanks for the detailed response. It seems like the issue might either be in:
github.com/git-lfs/git-lfs/tools.CopyWithCallback, orgithub.com/git-lfs/git-lfs/tq.(*basicDownloadAdapter).download.Can you
listthe first and second functions and post the output here, or share thepprofdump along with the binary that you ran it against?larsxschneider commentedon Aug 7, 2017
Hmm.. both don't look like the cluprit:
You can download the binary and the pprof dump here. The binary was build from this hash (with a minor modification, I changed this check to 5GB)
larsxschneider commentedon Aug 25, 2017
@ttaylorr I've tested the issue with the latest master and I see this error now:
git-lfs/commands/pull.go
Line 80 in 39c7bf6
Look at my
top... it looks likegit-lfsstarts way to manygitprocesses, no?ttaylorr commentedon Aug 25, 2017
@larsxschneider: very interesting. Let's see if we can figure out what arguments are being passed to those Git processes, and perhaps that will point us in the direction of where things are going wrong.
Could you try:
assuming that you are running this on a Linux box?
EDIT:
<pid>in the above snippet should be replaced with any of the running Git processes from the list above (or while Git LFS is running).larsxschneider commentedon Aug 26, 2017
#2453 and #2531 seem to fix this issue 🎉