Dear Bash Maintainers,
First and foremost, I wish to express my deep appreciation and utmost respect
for the titanic work you have accomplished over the decades in developing and
maintaining GNU Bash. While conducting high-frequency signal reliability tests 
on
long-running diagnostic scripts, we isolated a reproducible signal loss case
during command substitution parsing that we hope will be useful to you.

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Bash Version: 5.2
Patch Level: 21
Release Status: release

Description:
When a script with a registered signal trap (`trap '...' TERM INT`) repeatedly
evaluates command substitutions `$(...)` and receives the trapped signal while
Bash is internally parsing the command substitution (`parse_comsub`), Bash
intermittently emits a spurious syntax error:

    trap: line N: unexpected EOF while looking for matching `)'

When this occurs, the trap handler is aborted/not executed, and the main script
continues running as if the signal had never been received.

Across 300 trials on Ubuntu 24.04 (Bash 5.2.21, kernel 6.18), this results in
25 to 28 lost termination signals per 300 runs (approx. 8-9% failure rate).
Running the exact same test under `dash` results in 0 lost signals out of 300.

Repeat-By:
Run the following standalone harness:

#!/usr/bin/env bash
losses=0; trials=200
for (( i = 1; i <= trials; i++ )); do
        out=$(
            "$BASH" -c '
                trap "echo CAUGHT; exit 0" TERM
                while :; do
                    x=$( : $( :$( : ) ) )
                done
            ' 2>&1 &
        pid=$!
        sleep 0.03
        kill -TERM "$pid" 2>/dev/null
        sleep 0.05
        if kill -0 "$pid" 2>/dev/null; then
            kill -KILL "$pid" 2>/dev/null
        echo "LOST"
        fi
        wait "$pid" 2>/dev/null
    )
    [[ $out == LOST \vert{}\vert{}$out == "unexpected EOF" ]] && (( losses++ ))
done
printf 'Bash %s: %d lost signal(s) out of %d trials ' "$BASH_VERSION" "$losses" 
"$trials"

Thank you once again for your monumental contribution to the Unix and Linux
community, and for taking the time to examine this report.
With my highest regards and most respectful salutations,
Edgar Magdelaine

Reply via email to