URL: <https://savannah.gnu.org/bugs/?67745>
Summary: trap EXIT race in subshell produces inconsistent
results
Group: The GNU Bourne-Again SHell
Submitter: oxumbead
Submitted: Sat 29 Nov 2025 07:45:58 PM UTC
Category: None
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Unlocked
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Sat 29 Nov 2025 07:45:58 PM UTC By: oxumbead <oxumbead>
The script below produces two kinds of output:
$ while [ $(bash /tmp/test.sh fast | tee /dev/tty | wc -l) = 1 ] ; do date -u
; done
EXIT
Sat 29 Nov 2025 07:34:52 PM UTC
EXIT
Sat 29 Nov 2025 07:34:52 PM UTC
EXIT
EXIT
$ while [ $(bash /tmp/test.sh slow | tee /dev/tty | wc -l) = 1 ] ; do date -u
; done
EXIT
Sat 29 Nov 2025 07:36:11 PM UTC
EXIT
Sat 29 Nov 2025 07:36:12 PM UTC
EXIT
Sat 29 Nov 2025 07:36:13 PM UTC
EXIT
Sat 29 Nov 2025 07:36:14 PM UTC
EXIT
Sat 29 Nov 2025 07:36:15 PM UTC
EXIT
...
An alternate formulation of the reproduction uses:
sleep 2 &
# while : ; do : ; done &
I have tested this on 5.2.37 and 4.2.46.
The expected output comprises a single EXIT given that:
https://pubs.opengroup.org/onlinepubs/009604399/utilities/trap.html
> When a subshell is entered, traps that are not being ignored are set to the
> default actions.
https://www.gnu.org/software/bash/manual/bash.html
> Traps caught by the shell are reset to the values inherited from the
> shell’s parent, and traps ignored by the shell are ignored.
trap 'echo EXIT' 0
fast() {
while : ; do : ; done &
kill $!
}
slow() {
while : ; do : ; done &
sleep 1
kill $!
}
"$1"
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?67745>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
Description: PGP signature
