Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull hangs randomly

When using git on windows normally (such as git push and git pull), it will sometimes be very slow. Running git pull over and over again returns within two seconds most of the time, but about 1/6 of attempts take about a minute.

I have set git config --global core.preloadindex and git config --global core.fscache to true.

Examples after running set GIT_TRACE=1

Slow:

$ git pull
14:11:03.166594 git.c:371               trace: built-in: git 'pull'
14:11:03.168594 run-command.c:350       trace: run_command: 'fetch' '--update-head-ok'
14:11:03.186596 git.c:371               trace: built-in: git 'fetch' '--update-head-ok'
14:11:03.189596 run-command.c:350       trace: run_command: 'git-remote-https' 'origin' 'https://[...].git'
14:11:03.204598 run-command.c:350       trace: run_command: 'git credential-manager get'
14:11:46.400917 git.c:607               trace: exec: 'git-credential-manager' 'get'
14:11:46.400917 run-command.c:350       trace: run_command: 'git-credential-manager' 'get'
14:11:47.828059 run-command.c:350       trace: run_command: 'git credential-manager store'
14:11:47.869064 git.c:607               trace: exec: 'git-credential-manager' 'store'
14:11:47.869064 run-command.c:350       trace: run_command: 'git-credential-manager' 'store'
14:11:47.980075 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:47.991076 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:47.999077 git.c:371               trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:11:48.005077 run-command.c:1130      run_processes_parallel: preparing to run up to 1 tasks
14:11:48.005077 run-command.c:1162      run_processes_parallel: done
14:11:48.005077 run-command.c:350       trace: run_command: 'gc' '--auto'
14:11:48.014078 git.c:371               trace: built-in: git 'gc' '--auto'
14:11:48.017078 run-command.c:350       trace: run_command: 'merge' 'FETCH_HEAD'
14:11:48.025079 git.c:371               trace: built-in: git 'merge' 'FETCH_HEAD'
Already up-to-date.

Fast:

$ git pull
14:12:25.432820 git.c:371               trace: built-in: git 'pull'
14:12:25.434820 run-command.c:350       trace: run_command: 'fetch' '--update-head-ok'
14:12:25.451821 git.c:371               trace: built-in: git 'fetch' '--update-head-ok'
14:12:25.454822 run-command.c:350       trace: run_command: 'git-remote-https' 'origin' 'https://[...].git'
14:12:25.472824 run-command.c:350       trace: run_command: 'git credential-manager get'
14:12:25.497826 git.c:607               trace: exec: 'git-credential-manager' 'get'
14:12:25.497826 run-command.c:350       trace: run_command: 'git-credential-manager' 'get'
14:12:26.904967 run-command.c:350       trace: run_command: 'git credential-manager store'
14:12:26.941970 git.c:607               trace: exec: 'git-credential-manager' 'store'
14:12:26.941970 run-command.c:350       trace: run_command: 'git-credential-manager' 'store'
14:12:27.050981 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.060982 run-command.c:350       trace: run_command: 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.068983 git.c:371               trace: built-in: git 'rev-list' '--objects' '--stdin' '--not' '--all' '--quiet'
14:12:27.074984 run-command.c:1130      run_processes_parallel: preparing to run up to 1 tasks
14:12:27.074984 run-command.c:1162      run_processes_parallel: done
14:12:27.074984 run-command.c:350       trace: run_command: 'gc' '--auto'
14:12:27.082985 git.c:371               trace: built-in: git 'gc' '--auto'
14:12:27.085985 run-command.c:350       trace: run_command: 'merge' 'FETCH_HEAD'
14:12:27.092986 git.c:371               trace: built-in: git 'merge' 'FETCH_HEAD'
Already up-to-date.

Edit:

After running git config --global credential.helper "" the lines in output containing credential-manager are replaced by:

17:18:44.139589 run-command.c:350       trace: run_command: 'bash' '-c' 'cat >/dev/tty && read -r -s line </dev/tty && echo "$line" && echo >/dev/tty'
Password for 'https://[...]':

A delay occurs sometimes right before the Password line is displayed, with the same duration and frequency (as far as I can tell, from about 20 tests) as before.

like image 283
usernumber Avatar asked Feb 27 '17 13:02

usernumber


2 Answers

Based on your trace, it seems that the authentication step is slow. I can see two main reason to this:

  • The server sometimes responds slowly. You won't be able to do anything on the client side.
  • Something is wrong with authentication on your side. The most probable cause I think, is that you may use a credential manager which cause the slowness. Try to disable it.
like image 188
Guillaume Pascal Avatar answered Oct 04 '22 14:10

Guillaume Pascal


TL;DR - My slow git (GCM) was fixed by disabling .net assembly binding on my machine (via fuslogvw).

I discovered it was due to a slow git credentials manager (GCM) by running git and the GCM in trace mode:

$ SET GIT_TRACE=1 
$ SET GCM_TRACE=1
$ git fetch

The logs showed the GCM was slow. When looking at the GCM with sysinternals' process monitor to figure out what was happening, I saw it was writing heavily to disk.

Now, it turned out the GCM is a .net process, and I had configured .net to log all assembly binds to disk for debugging some process a couple of days ago (via fuslogvw - fusion log viewer).

Disabling the binding logging fixed my problem and speed returned to normal.

like image 21
Martijn Evens Avatar answered Oct 04 '22 15:10

Martijn Evens