_jcd_show_tab_busy_indicator infinite loop can cause 100% CPU usage if not properly killed

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
50/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
bash, shell
Domain
cli, performance

Research direction

Read jcd_function.sh lines 294-311, starting with _jcd_show_tab_busy_indicator and how its parent starts or stops it. Reproduce the tab-completion scenario if possible, then verify the indicator cannot run indefinitely or leave a process consuming CPU. Done means the busy indicator has a bounded lifetime while preserving its intended animation.

Written by the indexing model from the issue text.

Description

Description

The _jcd_show_tab_busy_indicator() function in jcd_function.sh contains an unbounded while true loop that can orphan and consume 100% CPU if the parent process fails to kill it properly.

Location

jcd_function.sh lines 294-311:

_jcd_show_tab_busy_indicator() {
    sleep 0.5
    local dot_count=0
    while true; do
        tput rc >&2
        tput el >&2
        # ... animation code ...
        sleep 0.3
    done
}

Steps to Reproduce

The exact trigger is unclear, but after extended use of jcd tab completion, a bash session became stuck at 100% CPU with the process in state R+ (running, foreground). The process accumulated over 10 minutes of CPU time and was resistant to SIGKILL.

Environment

  • Linux (Debian-based)
  • Bash 5.x
  • jcd sourced via .bashrc

Suggested Fix

Add a maximum iteration limit or timeout to prevent infinite spinning:

_jcd_show_tab_busy_indicator() {
    local max_iterations=100  # ~30 seconds max
    local count=0
    sleep 0.5
    while [[ $count -lt $max_iterations ]]; do
        tput rc >&2
        tput el >&2
        case $((count % 4)) in
            0) printf "" >&2 ;;
            1) printf "." >&2 ;;
            2) printf ".." >&2 ;;
            3) printf "..." >&2 ;;
        esac
        count=$((count + 1))
        sleep 0.3
    done
}
Dominant language
Shell
Stars
175
Forks
19
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/Sysinternals-jcd

All issues in microsoft/Sysinternals-jcd

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.