Re: bash 5.3: here-document larger than PIPE_BUF deadlocks on macOS (pipe-backed heredoc, body written before reader is forked)

Julián Mateu <[email protected]> Sat, 11 Jul 2026 10:05:50 +0100
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAC-m2iF1rQ283EAETqDLL+AEsjCj3wRkdumjZnXg_0sTASSYyw@mail.gmail.com>
--00000000000092fa860656522deb
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

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=3Dos.pipe();os.set_blocking(w,False);t=3D0
    try:
      while True: t+=3Dos.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=3D65536.

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 <[email protected]> wrote:

> On 7/10/26 6:28 AM, Juli=C3=A1n 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 rece=
nt
> 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 <=3D doc <=3D 4096, 4096 <=3D doc <=3D 65536, an=
d 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 encounte=
r
> 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 pip=
e
> buffer size using F_GETPIPE_SZ. It would be nice if macOS offered somethi=
ng
> similar.
>
> >
> > Repeat-By (self-contained, no external tools; run under bash 5.3 on
> macOS):
> >
> >        printf -v body '%*s' 600 ''    # 600-byte body
> >        body=3D${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=3D${body// /x}
> cat <<EOF
> $body
> EOF
> echo done # never printed on bash 5.3 / macOS
> $ ../bash-5.3-patched/bash ./x2
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
xx
> 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    [email protected]    http://tiswww.cwru.edu/~chet/
>

--00000000000092fa860656522deb
Content-Type: text/x-python-script; charset="US-ASCII"; name="pipes.py"
Content-Disposition: attachment; filename="pipes.py"
Content-Transfer-Encoding: base64
Content-ID: <f_mrg4ytqz0>
X-Attachment-Id: f_mrg4ytqz0

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoiIiIKRGV0ZXJtaW5pc3RpYyByZXByb2R1Y2VyIGZvciB0
aGUgYmFzaCA1LjIgbWFjT1MgaGVyZS1kb2N1bWVudCBoYW5nLgoKTWVjaGFuaXNtIChwZXIgYnVn
LWJhc2ggMjAyNi0wMi9tc2cwMDEyNik6IHJlY2VudCBYTlUgc2l6ZXMgcGllcyBkeW5hbWljYWxs
eQooNTEyIEIgLi4gNjQgS2lCKSBidXQgb25seSAqZ3Jvd3MqIHRoZW0gd2hpbGUgdG90YWwgc3lz
dGVtIHBpcGUgbWVtb3J5IGlzIHVuZGVyCnRoZSAxNiBNaUIgYG1heHBpcGVrdmFgIGhpZ2gtd2F0
ZXIgbWFyay4gSG9tZWJyZXcgYmFzaCB3YXMgYnVpbHQgYmVsaWV2aW5nIGEKcGlwZSBob2xkcyA2
NCBLaUIgKEhFUkVET0NfUElQRVNJWkUpLCBzbyBpdCB3cml0ZXMgYSBtZWRpdW0gaGVyZWRvYyBp
bnRvIGEgcGlwZQpCRUZPUkUgZm9ya2luZyB0aGUgcmVhZGVyLiBJZiB0aGUgbWFjaGluZSBpcyBv
dmVyIHRoZSBtYXJrLC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