Repository navigation
A closed stdout or stderr reader ends a program by SIGPIPE, not with an error (#1467) - #1470
Merged
Merged
Conversation
…an error (bendlang#1467) A write to a standard stream whose reader has left (EPIPE) printed "bend: a short write on a standard stream" and exited 1. It now ends the program by SIGPIPE, silently, as `yes | head -1` does (status 141 in a shell). Any other write error keeps the message and exit 1, and files and sockets keep answering Fail: io_loop still ignores SIGPIPE. C: io_out and io_sync share io_lost, which on EPIPE restores SIGPIPE's default disposition and raises it. JS: Bun ignores SIGPIPE too, and adding then removing a listener restores the default (Bun 1.2 and 1.4), so io_out does that and signals itself. tests/io/stream_epipe has each lane's child write through the runtime's own io_out to a pipe whose read end is closed and print its status.
viridale
force-pushed
the
fix-1467-epipe-sigpipe
branch
from
October 10, 2026 03:04
14ddd00 to
f730331
Compare
Lorenzobattistela
approved these changes
Oct 10, 2026
Merged
viridale
added a commit
to viridale/bend-cli
that referenced
this pull request
Oct 20, 2026
2.0.37, the minimum Bend, includes bendlang/bend#1470, so a closed stdout pipe ends the program by SIGPIPE (status 141, nothing on stderr), natively and under Bun, including through io_sync before exit. The README's note for older releases goes. It also adds Base's IO.exit (#1492), which exits silently with 0..255, while main's U32 result stays ignored by design; AGENTS.md now names it. bendlang/bend#1463 was closed by #1558, which keeps the unused-foreign- import failure by design, so AGENTS.md cites that instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1467.
A program whose stdout or stderr reader exits early (
./flood | head -1,bun flood.js | head -1,bend flood.bend | head -1) printedbend: a short write on a standard streamand exited 1. Now a write to a standard stream that fails with EPIPE ends the program by SIGPIPE, silently, the wayyes | head -1does: status 141 in a shell, still non-zero forpipefail. Any other write error (EBADF, ENOSPC, EIO) keeps the message and exit 1. Files and sockets keep answeringFail, becauseio_loop'ssignal(SIGPIPE, SIG_IGN)is untouched.io_outandio_syncshare a newio_lost. On EPIPE it restores SIGPIPE's default disposition and raises it; otherwise it callserr_failas before. It is host-only (inside#if !DEVICE), like the rest of the IO runtime.signal(). Adding and then removing a listener restoresSIG_DFL(onDidChangeListenersinBunProcess.cppcallssignal(n, SIG_DFL)when the count drops to 0;removeAllListenerstakes that path, the same in Bun 1.2.23 and 1.4.0), soio_outdoes that and sends SIGPIPE to itself. The in-processbend f.bendrun uses the sameio_out.tests/io/stream_epipe.bendhas a.cand a.jstwin. The C twin forks a child that moves fd 1, then fd 2, onto a pipe whose read end is already closed and writes a line throughio_out/io_sync. The JS twin spawns a child bun that runs the runtime's ownio_out(${io_out}) the same way. Each answers the child's status as a shell shows it, and expects141. On main all three lanes print the message and1instead. Closing the read end before the write keeps it deterministic.Verification (macOS arm64, Apple clang 21, Bun 1.2.23)
flood.bend:./flood | head -1,bun flood.js | head -1,bun bend2/main.ts flood.bend | head -1and./flood 2>&1 | head -1give141 0with nothing on stderr (main:1 0and the message). A full run still exits 0../flood >&-(EBADF) still prints the message and exits 1.tests/ioandtests/halt, run locally the way onegates/test.tsshard runs them (checkup, then the C and JS lanes): PASS 196 / 196, the new test included.bun gates/repo.ts: PASS 54 / 54. comp.ts is at 63,997 ttok of 64,000 (main: 63,905), so there are only 3 tokens of room. I shortened the comments to fit, and the merge queue will recount.Not run: the cluster gates (
test.tson the minis,perf.ts) and Linux. The Bun 1.4.0 listener-removal path was checked in Bun's source, not run.