bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash 5.3: here-document larger than PIPE_BUF deadlocks on macOS (pip


From: Julián Mateu
Subject: Re: bash 5.3: here-document larger than PIPE_BUF deadlocks on macOS (pipe-backed heredoc, body written before reader is forked)
Date: Sat, 11 Jul 2026 10:05:50 +0100

Thanks for the fast and detailed reply, and for the pointer to msg00126, I
really appreciate it! That explains it completely, and corrects my
diagnosis. You're right that PIPE_BUF is about write atomicity, not
capacity; I conflated the two because the numbers coincide.

I now agree this is a duplicate of msg00126. I can confirm the maxpipekva
theory directly on the affected machine. Measuring the actual capacity of a
fresh pipe with no reader:

    python3 -c 'import os;r,w=os.pipe();os.set_blocking(w,False);t=0
    try:
      while True: t+=os.write(w,b"x"*64)
    except BlockingIOError: print(t)'

    -> 512

So this machine is sitting above the 16 MiB maxpipekva high-water mark and
the kernel is handing out minimum-size (512-byte) pipes, while the Homebrew
bash was built with HEREDOC_PIPESIZE=65536.

That also explains what previously looked like nondeterministic behaviour
to me: the hang only happens when the whole-system pipe memory is above the
threshold, so it's not just the here-document size. A reboot drops pipe kva
back under the mark and the same script runs fine (that explains why it
does not reproduce in your machine). In my case, I'm running a lot of
long-lived pipes (tmus, editors, claude-code, bats test suites, etc). I now
have a python script that reproduces this by first creating several pipes
(attached only in case it helps), providing the path to the bash binary as
the first argument can be used to deterministically verify if the issue is
solved.

Happy to test the devel-branch fix on macOS 26 when it lands.

System details, in case they help:
  macOS 26.5.1 (Darwin 25.5.0, arm64, xnu-12377.121.6)
  bash 5.3.15, Homebrew, poured from a prebuilt bottle (not built locally)

On Fri, 10 Jul 2026 at 14:06, Chet Ramey <chet.ramey@case.edu> wrote:

> On 7/10/26 6:28 AM, Julián Mateu wrote:
>
> > Bash Version: 5.3
> > Patch Level: 15
> > Release Status: release (installed via Homebrew; per the mechanism
> below, a
> > from-source build should also reproduce)
>
> This appears to be very system-specific and the result of changes in recent
> versions of macOS; see
>
> https://lists.gnu.org/archive/html/bug-bash/2026-06/msg00126.html
>
> for a detailed explanation.
>
> Bash computes the pipe size at build time and assumes it doesn't change,
> and, that if it does, there is a way to determine it at runtime.
>
> I've never hit this on macOS 15 or 26, and the bash test suite uses here-
> documents with sizes 512 <= doc <= 4096, 4096 <= doc <= 65536, and larger
> than 65536. I would be shocked if the person who packaged bash for
> homebrew didn't run the test suite, so we can assume they didn't encounter
> this, either.
>
> > Description:
> > On macOS, a here-document whose body exceeds PIPE_BUF (512 bytes on
> Darwin)
> > makes bash 5.3 hang forever.
>
> As above, the issue is a little bit more dynamic than that. Plus PIPE_BUF
> is about write atomicity on pipes, not pipe capacity.
>
>
> > bash on Linux (64 KB pipe buffers) are
> > unaffected.
>
> One nice feature Linux has is the ability to dyamically determine the pipe
> buffer size using F_GETPIPE_SZ. It would be nice if macOS offered something
> similar.
>
> >
> > Repeat-By (self-contained, no external tools; run under bash 5.3 on
> macOS):
> >
> >        printf -v body '%*s' 600 ''    # 600-byte body
> >        body=${body// /x}
> >        cat <<EOF
> >        $body
> >        EOF
> >        echo done # never printed on bash 5.3 / macOS
>
> This is bash-5.3 on macOS: the first is a locally-built bash-5.3.15; the
> second is from Macports.
>
> $ uname -a
> Darwin Mac.lan 24.6.0 Darwin Kernel Version 24.6.0: Tue Apr 21 20:15:34
> PDT
> 2026; root:xnu-11417.140.69.710.16~1/RELEASE_ARM64_T6031 arm64
> $ cat x2
> printf -v body '%*s' 600 ''    # 600-byte body
> body=${body// /x}
> cat <<EOF
> $body
> EOF
> echo done # never printed on bash 5.3 / macOS
> $ ../bash-5.3-patched/bash ./x2
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxx
> done
>
> There will be a fix derived from the bug-bash message above in the next
> devel branch push.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                  ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/
>

Attachment: pipes.py
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]