Skip to content

Instantly share code, notes, and snippets.

@azat
Last active June 15, 2022 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azat/affbda3f8c6b5c38648d4ab105777d88 to your computer and use it in GitHub Desktop.
Save azat/affbda3f8c6b5c38648d4ab105777d88 to your computer and use it in GitHub Desktop.
bash bug: wait_for: No record of process (had been fixed in bash 5.1+)
#!/usr/bin/env bash
#
# Reproducer for bash bug that had been fixed in bash 5.1+ [1], report [2]
#
# [1]: https://git.savannah.gnu.org/cgit/bash.git/commit/?h=bash-5.1&id=8868edaf2250e09c4e9a1c75ffe3274f28f38581
# [2]: https://lists.gnu.org/archive/html/bug-bash/2019-05/msg00110.html
#
function thread_worker()
{
set -e
# echo "thread_worker_pid=$BASHPID (started)"
trap "STOP_THE_LOOP=1; sleep 0.5" INT
STOP_THE_LOOP=0
while [[ $STOP_THE_LOOP != 1 ]]; do
sleep 0.1 | grep foo || :
done
# echo "thread_worker_pid=$BASHPID (finished)"
}
function main()
{
echo "main_pid=$BASHPID"
local pids=()
for i in $(seq 0 100); do
thread_worker &
pids+=( $! )
done
sleep 0.1
echo "Sending INT"
wait &
sleep 0.1
kill -INT "${pids[@]}"
sleep 0.1
wait
}
main "$@"
@azat
Copy link
Author

azat commented Jun 15, 2022

$ timeout -v 1m bash -c 'while docker run --rm -v $PWD:/wrk -w /wrk bash:5.1 ./test5.sh; do :; done |& fgrep -m1 wait_for:'
timeout: sending signal TERM to command ‘bash’
$ timeout -v 1m bash -c 'while docker run --rm -v $PWD:/wrk -w /wrk bash:5.0.17 ./test5.sh; do :; done |& fgrep -m1 wait_for:'
/wrk/test5.sh: line 1: wait_for: No record of process 616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment