ohmyzsh: Oh My Zsh hangs because of slow `git status` calls

Describe the bug

Oh My Zsh makes my terminal hang after a command completes in Linux. I also found this Linux forum post which helped me confirm that Oh My Zsh is the culprit.

This happens to me on a Ubuntu VM inside Virtualbox, but it may generalise to non-VM setups. In my VM I have a project/ folder, in which I have mounted a very large data/ folder (34GB). This problem only happens when the folder is mounted.

Whenever I cd to the project folder / any of its subfolders (not necessarily the data folder), or run a command (eg ls), the command completes but my terminal hangs for a very long time (around the same amount of time it took for the directory to mount…). If I hit Ctrl + C then the terminal stops hanging and the command has completed, but the zsh prompt is just ->.

When I uninstall Oh My Zsh, the issue dissappears. Experimentation shows that I get the issue when I mount my directory with vboxsf or via my network with SMB, but not when the data exists directly inside my VM. Oh My Zsh must be doing something with those mounts after each command…

To Reproduce

  • Run Ubuntu VM (e.g. Virtualbox)
  • mount a large volume to the VM (E.g. with vboxsf or SMB via a network share)
  • cd to the parent directory of that volume
  • Wait a long time for the command to finish

Expected behavior

Shell becomes responsive after commands finish, like in normal zsh.

Desktop (please complete the following information):

  • OS / Distro: Ubuntu VM inside Virtualbox
  • Latest ohmyzsh Update?: Yes
  • ZSH Version: Latest
  • Terminal emulator: Any

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

@JulianFerry Instead of hiding untracked files entirely via git status -uno, I suggest another workaround. In git.zsh line 9, add a timeout [duration] prefix, like the following:

- GIT_OPTIONAL_LOCKS=0 command git "$@"
+ GIT_OPTIONAL_LOCKS=0 command timeout 1s git "$@"

This way, dirty git folders can be highlighted properly, as long as it doesn’t hang the terminal. 😃

@JulianFerry Instead of hiding untracked files entirely via git status -uno, I suggest another workaround. In git.zsh line 9, add a timeout [duration] prefix, like the following:

- GIT_OPTIONAL_LOCKS=0 command git "$@"
+ GIT_OPTIONAL_LOCKS=0 command timeout 1s git "$@"

This way, dirty git folders can be highlighted properly, as long as it doesn’t hang the terminal. smiley

Is there any way to do this in a zshrc or does git.zsh itself need to be modified?

You can modify the __git_prompt_git function in your zshrc file:

__git_prompt_git () {
	GIT_OPTIONAL_LOCKS=0 command timeout 1s git "$@"
}

Just to bump this thread: Do the ohmyzsh developers think this is worth addressing? Perhaps by including the git message:

It took 13.57 seconds to enumerate untracked files. 'status -uno'

Confirmed on VM Player! : )

It’s such a relief to have that fixed. Thanks