Hi, I'm forwarding a bug report originally reported in <https://bugs.debian.org/822605>.

When a builtin function like echo fails to write to a named pipe, bash will receive a SIGPIPE that will terminate the whole shell.

To reproduce this issue:

In shell 1:

    $ rm -f /tmp/f && mkfifo /tmp/f && \
    (i=0; while true; do echo $((i=i+1)) > /tmp/f; done); \
    echo "terminated with exit status $?"

In shell 2:

    $ while true; do echo $(< /tmp/f); done

The command in the first shell will exit after a random number of iterations with "terminated with exit status 141".

The reason for the SIGPIPE is a race condition illustrated in [1].

Regardless of the reason for the SIGPIPE, the reporter expects the loop to carry on indefinitely (`while true; ...`).

One possible solution suggested in [1] is:

it is incorrect that > SIGPIPE terminates the subshell.

When bash runs a builtin command without forking, it should install
a SIGPIPE handler that will cause that signal to abort the command
but not terminate the shell.
If this behavior is desired and not considered a bug, then the bash manual should describe it in the SIGNALS section.

Regards,

[1] https://bugs.debian.org/822605#26

--
Gioele Barabucci

Reply via email to