zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Rudi C <rudiwillalwaysloveyou@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [Fixed Hardwrap][BUG] Pipe fails even when using ' || true '
Date: Fri, 26 Mar 2021 10:16:14 -0700	[thread overview]
Message-ID: <CAH+w=7bt8DzR8QV=nAB2zhPib5x5KY7BVGs1BaZW2PTPWUw9Cw@mail.gmail.com> (raw)
In-Reply-To: <CAE9z9A2RBrXpEHxh92+TMTbP25+ztdzC_ZcuTpegb32Gxd4KUQ@mail.gmail.com>

On Fri, Mar 26, 2021 at 6:09 AM Rudi C <rudiwillalwaysloveyou@gmail.com> wrote:
>
> This pipe unexpectedly fails:
>
> ```
> $ setopt pipefail
> $ { print -nr -- "x" || true } | eval 'print -rn -- "${(q+@)brish_stdin}"' ; echo $'\n'Returned $?:"${(j.|.)pipestatus[@]}"
> ''
> Returned 141:141|0
> ```

Exit status 141 indicates that the entire { ... } construct was killed
by SIGPIPE,which is occurring because there's nothing in the "eval" on
the right side to read the output from "print".

Whether this happens depends on order of events (does the right side
of the pipe exit before the left side finishes printing) which can in
turn depend on OS-level process scheduling algorithms over which zsh
has little or no control; or because of pipe buffering, which is also
an OS thing, although with only one character sent on the pipe that is
unlikely to be the cause in this case.

> The behavior is nondeterministic on macOS, and it actually doesn't usually fail at all!

See "order of events".  Process scheduling may depend on how many
actual cores are in the CPU, for example, determining whether the
pipeline executes in true parallel fashion or via time-slicing.

> BTW, there seems to be another weird thing going on; Adding two spaces before `echo` breaks the whole loop both on Linux and macOS:

If you're copy-pasting from an edit in browser gmail, for example, it
has a tendency to insert non-breaking spaces whenever there is more
than one consecutive space, which the shell interprets as
non-whitespace and attempts to execute as commands.  Annoys the hell
out of me whenever I forget that it happens.


  reply	other threads:[~2021-03-26 17:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-26 13:09 Rudi C
2021-03-26 17:16 ` Bart Schaefer [this message]
2021-03-27  8:30   ` Mikael Magnusson
2021-03-27  8:32     ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bt8DzR8QV=nAB2zhPib5x5KY7BVGs1BaZW2PTPWUw9Cw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rudiwillalwaysloveyou@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).