The purpose of the code is to synchronize the output of the command
redirection run "inside" `tee` with the rest of the script. For that,
the "main process" blocks on flock until the command inside redirection
is finished when it unlocks the flock.
However on bash 5.0 The `cat` inside `tee` gets blocked on `read()`.
I have created the following oneliner as an reproducible example:
If I execute it on on any bash<=4 I get `all ok` printed out.
However when run under mine kernel 5.2.11, coreutils 8.31, bash
version 5.0.9(1) on my updated archilinux, the `cat` inside `tee >(cat
...)` gets stuck. The `echo "all ok"` is never executed. The `timeout 1`
fires and `not ok` is printed out. I have also tried `docker run
bash:5.0` and various servers I can access - `not ok` is printed out on
bash v5.
I can also replicate the behavior on `docker run bash:5.0`
I tried inspecting both `tee` and `cat` under `strace`. Well,
`tee` does `close(3)` , where 3 is it's file descriptor to command
redirection. And `cat` just blocks on `read()` call. The empty line from
`echo |` is printed out by `cat`, you can put something in there, for
sure it reads from proper stream. bash<4 closed the stream properly,
bash5.0 seems like doesn't do that and the stream is still open and
`cat` blocks on `read()` call.