`wait` triggers an infinite loop when used in an EXIT trap

Aleksey Covacevice <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <[email protected]>
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt 
-fexceptions         -Wp,-D_FORTIFY_SOURCE=3 -Wformat 
-Werror=format-security         -fstack-clash-protection 
-fcf-protection         -fno-omit-frame-pointer 
-mno-omit-leaf-frame-pointer -g 
-ffile-prefix-map=/build/bash/src=/usr/src/debug/bash -flto=auto 
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' 
-DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' 
-DSYS_BASH_LOGOUT='/etc/bash.bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS 
-std=gnu17
uname output: Linux work 6.17.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 24 
Nov 2025 15:21:09 +0000 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.3
Patch Level: 8
Release Status: release

Description:
     `wait` triggers an infinite "pid is not a child of this shell" loop 
when
     used in an EXIT trap.

Repeat-By:
     Run the following:

         jobs=()

         cleanup() {
             kill -- "${jobs[@]}"
             wait
         }

         trap cleanup EXIT

         true & jobs+=($!)
         true & jobs+=($!)
         true & jobs+=($!)
         true & jobs+=($!)
         true & jobs+=($!)

     Ocasionally bash loops at `wait` claiming some "pid is not a child of
     this shell". (It doesn't happen if `kill` is not used.)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.