Skip to content

Terminal closure leaves orphaned zsh subshell with high CPU in zsh <5.10 #372

Description

@LangLangBart

to reproduce

Use the docker/podman command on the project's readme, including a --name flag
to connect more easily from another terminal.

podman run --name BUG_TEST  -e TERM -e COLORTERM \
  -e LC_ALL=C.UTF-8 -w /root -it --detach-keys="ctrl-^,ctrl-@" \
  --rm alpine sh -uec '
  apk add zsh curl tmux
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/romkatv/zsh4humans/v5/install)"'

Options selected for z4h setup:

1   keyboard
1   keybindings
n   tmux
n   direnv
y   login shell

y   diamond
y   lock
... (prompt preferences do not matter for this bug, pick as you like)

Connect to 'BUG_TEST' in another terminal and run top to monitor processes.

podman exec -it BUG_TEST top

Go back to your original terminal where z4h was setup.

Run ls -l<TAB> and without making a selection from the fzf window. Press
ctrl-z while the fzf window is open until the fzf window with the selection
options is no longer visible. You may need to press ctrl-z twice.

Go back to the terminal window where the podman exec -it BUG_TEST top is
running. You should notice a zsh process that consumes a non-trivial amount of
CPU, in my case ~20%.

Mem: 566852K used, 1425028K free, 932K shrd, 2048K buff, 269824K cached
CPU:  19% usr   0% sys   0% nic  79% idle   0% io   0% irq   0% sirq
Load average: 0.95 0.49 0.20 2/212 988
  PID  PPID USER     STAT   VSZ %VSZ CPU %CPU COMMAND
  979   977 root     R     8420   0%   1  20% zsh -i
  980   979 root     T     696m  36%   2   0% /root/.cache/zsh4humans/v5/fzf/bin/fzf --query=^- --color=hl:201,hl+:201 --with-nth=2 --delimiter=\000 --ansi --exact --no-mouse --tie
  977     1 root     S     8420   0%   0   0% zsh -i
    1     0 root     S     8388   0%   3   0% zsh -i
  935     1 root     S     7132   0%   0   0% zsh -i
  936     1 root     S     7116   0%   0   0% zsh -i
  970     0 root     R     1708   0%   2   0% top

If you close all terminal windows and check your local CPU usage on your system,
you should notice a spike related to Docker/Podman processes until you run
podman kill BUG_TEST.

ps x -ro user,pid,pcpu,pmem,etime,comm | head -10

# USER    PID  %CPU %MEM  ELAPSED COMM
# hans  1400 100.1  4.1 12:03:32 /System/Library/Frameworks/Virtualization.framework/Versions/A/XPCServices/com.apple.Virtualization.VirtualMachine.xpc/Contents/MacOS/com.apple.Virtualization.VirtualMachine

I can consistently reproduce the z4h-fzf-complete bug on my MacBook using the
default .zshrc.mac file from zsh4humans as my zshrc with one extra line:

# easier to reproduce the issue with tmux off
zstyle ':z4h:' start-tmux false

When I set it up and opened Apple's default Terminal, entered ls -<TAB>, and
instead of pressing 'ctrl-z' just quit the entire terminal window, it always
spawns a single zsh process that continuously uses 100% CPU and runs
indefinitely until I manually kill it.

Added GIF to make the described issue clearer:

Image


The issue is no longer reproducible with the zsh development version. I was able
to pinpoint it to the following commit where the issue no longer occurs:

Is there a way to mitigate the issue until zsh devs release version 5.10?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions