Closed jolmg closed 5 years ago
As a workaround, pipes can be put in subshells, like so:
@test "foo" {
sleep 10h &
trap 'kill $!' EXIT
echo begin > /dev/tty
( echo bar | cat ) > /dev/tty
echo end > /dev/tty
}
That avoids the freezing.
I forgot to mention the versions I'm working with:
$ bats --version
Bats 0.4.0
$ bash --version
GNU bash, version 5.0.7(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
I just found out this is an obsolete repo. I tried to replicate this bug in bats-core v1.1.0 and it doesn't happen, so I'm going to close this.
Hello. I'm not sure if this is a bash issue or a bats issue, but since I can't get this to replicate outside of bats, I figured I'd try here first.
Here is an example file (I'll call it
t.bats
):On running
bats t.bats
I get the output:and then it stays frozen. I can't
Ctrl-C
out of it, either. I have to doCtrl-Z
,kill %
.If I remove
| cat
or remove the backgrounded process, it doesn't freeze.Checking
strace
, it seems it's stuck waiting for all child processes to die:I got a backtrace of bash from
gdb
: bash-bats-freeze-backtrace.txt. Here are the first few lines:This is apparently waiting for the pipeline to die. It calls
wait_for
with a particular pid, but for some reason that results in it waiting on all child processes.wait_for
callswaitchld
with the pid and asking it to block, andwaitchld
decides clean up existing dead child processes while respecting the block parameter, so it blocks until all child processes are dead.A comment on
waitchld
says (emphasis mine):and then follows with the code:
In the freezing execution,
waitpid_flags
is0
, andWNOHANG
is1
.It looks inconsistent with the comment, which makes me suspect the problem is with bash. However, I'd like to be able to replicate this without the use of bats before trying to bring this up with the bash developers. I don't know what bats does that makes this behavior turn up. Can someone here confirm where the problem is?