Repository navigation
Description
Version: tsrs 0.25.0-ts7.1.0-beta (@tsrs/linux-x64-gnu), Linux x64.
What happens
When the native tsrs binary's stdout is a pipe in O_NONBLOCK mode and the reader falls behind, tsrs stops writing once the pipe buffer fills. It discards the rest of its output and prints nothing on stderr. The exit code is unchanged, so a caller cannot tell the output is incomplete:
--listFilesOnlystops at exactly 65,536 bytes and exits0.- A check with 5,000 errors prints 841 of them and exits
2.
tsc from typescript@7.1.0-beta prints all of its output under the same conditions.
This is the binary-level side of #830. That issue was closed after the npm launcher started clearing O_NONBLOCK before execve (#831). The binary still drops output whenever it inherits a non-blocking stdout, from any parent: a Bun-hosted launcher (as discussed in #830), a process supervisor, or another tool that shares the pipe.
Reproduction
repro.py runs a command with stdout on a pipe, either blocking or O_NONBLOCK, and starts reading after one second:
import os, subprocess, sys, time
mode, cmd = sys.argv[1], sys.argv[2:]
r, w = os.pipe()
os.set_blocking(w, mode == "blocking")
p = subprocess.Popen(cmd, stdout=w, stderr=subprocess.PIPE)
os.close(w)
time.sleep(1) # let the pipe buffer fill before reading
out = b""
while chunk := os.read(r, 1 << 16):
out += chunk
err = p.stderr.read()
print(f"{mode:12} exit={p.wait()} stdout={len(out):>7} bytes, {out.count(b'error TS'):>4} diagnostics, stderr={err[:80]!r}")npm i tsrs@0.25.0-ts7.1.0-beta typescript@7.1.0-beta
# 5,000 type errors
python3 -c "open('a.ts','w').write(''.join(f'export const v{i}: number = \"x\";\n' for i in range(5000)))"
echo '{"compilerOptions":{"strict":true,"noEmit":true},"files":["a.ts"]}' > tsconfig.json
# 2,000 files, for a --listFilesOnly listing larger than 64 KiB
mkdir many && python3 -c "
for i in range(2000): open(f'many/module_with_a_reasonably_long_name_{i:04}.ts','w').write(f'export const v{i} = {i};\n')"
echo '{"compilerOptions":{"strict":true,"noEmit":true},"include":["many/**/*.ts"]}' > tsconfig.files.json
TSRS=node_modules/@tsrs/linux-x64-gnu/tsrs
TSC=node_modules/@typescript/typescript-linux-x64/lib/tsc
for m in blocking nonblocking; do python3 repro.py $m $TSRS -p tsconfig.json --pretty false; done
for m in blocking nonblocking; do python3 repro.py $m $TSRS -p tsconfig.files.json --listFilesOnly; done
for m in blocking nonblocking; do python3 repro.py $m $TSC -p tsconfig.json --pretty false; done
for m in blocking nonblocking; do python3 repro.py $m $TSC -p tsconfig.files.json --listFilesOnly; doneOutput:
# tsrs, 5,000 errors
blocking exit=2 stdout= 393893 bytes, 5000 diagnostics, stderr=b''
nonblocking exit=2 stdout= 65490 bytes, 841 diagnostics, stderr=b''
# tsrs, --listFilesOnly
blocking exit=0 stdout= 389448 bytes, 0 diagnostics, stderr=b''
nonblocking exit=0 stdout= 65536 bytes, 0 diagnostics, stderr=b''
# tsc 7.1.0-beta, 5,000 errors
blocking exit=2 stdout= 393893 bytes, 5000 diagnostics, stderr=b''
nonblocking exit=2 stdout= 393893 bytes, 5000 diagnostics, stderr=b''
# tsc 7.1.0-beta, --listFilesOnly
blocking exit=0 stdout= 390978 bytes, 0 diagnostics, stderr=b''
nonblocking exit=0 stdout= 390978 bytes, 0 diagnostics, stderr=b''
Where we hit it
A test read bunx tsrs --listFilesOnly through a Node spawnSync call, inside a parallel Vitest run (Bun 1.4.4, Node 26, Linux x64). In CI, and in a local run of the same suite, the listing came back incomplete while tsrs exited 0, so the test got the wrong answer. Locally the listing ended partway through a path, after 657,792 of 934,790 bytes. Run on its own, the same command always printed everything, and we could not isolate which process made the pipe non-blocking under load. Redirecting the listing to a regular file fixed it.
The exit-0 case worries us most: a caller of --listFilesOnly that trusts the exit code acts on a partial list.
Expected
tsrs writes all of its output, as tsc does. When a write returns EAGAIN, it waits for the descriptor to become writable (poll) and retries. Alternatively, it reports a write error on stderr and exits non-zero. The triage branch in #830 cleared O_NONBLOCK in the binary, which covers the launcher case, but not a descriptor that another process switches to non-blocking while tsrs runs.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
oxc-captain commentedon Nov 17, 2026
crates/tsrs_cli/tests/integration/nonblocking_stdout.rs(integration regression)This only triggers when
tsrsinherits a non-blocking stdout pipe, but in that case it can return an exit-0--listFilesOnlylist that is silently truncated, which callers may act on. There is a workaround (redirect to a regular file), so it is not release-blocking.The root cause is in
crates/tsrs_execute/src/sys.rs.OsSyswrites to aBufWriter<std::io::Stdout>and only treatsBrokenPipeas fatal;ErrorKind::WouldBlock(the Rust mapping ofEAGAINon a full non-blocking pipe) is silently discarded. Go'scmd/tsc/sys.gousesos.Stdout, and the Go runtime parks the goroutine and polls the descriptor onEAGAIN, so the Go compiler blocks until the reader drains the pipe. Instrumentation confirmedWouldBlockis hit exactly when output stops.I found a potential fix for this issue. The branch wraps stdout in a
StdoutWriterthat polls forPOLLOUTand retries onWouldBlock/Interrupted, matching the Go runtime behavior while preserving the existing SIGPIPE handling fortsc | head. It also adds integration regression tests for both diagnostics and--listFilesOnlyon a non-blocking pipe.Full Triage Report
Issue 1015 — Reproduction Report
Claim
When the native
tsrsbinary inherits a stdout pipe that is inO_NONBLOCKmode, it stops writing once the pipe buffer fills, silently discards the
remaining output, and exits with the same status code as if it had printed
everything. The pinned TypeScript Go compiler (
tsc-go) prints all of itsoutput under identical conditions.
non-blocking pipe, while
tsc-goprints all 5,000.--listFilesOnlyon a project whose listing is larger than 64 KiB:tsrs stops at exactly the pipe-buffer size (65,536 bytes);
tsc-goprints the complete listing.
Environment
target/debug/tsrs, built from this tree at7eb504db5ce54d160a73399fadd30f7f695681c1Version 7.1.0-beta (tsrs 7.1.0-beta.tsrs2, microsoft/TypeScript@3e9236361fa9)triage/gh-1015/ts-ref/tsc/tsc-go, built fromMicrosoft/TypeScript tag
v7.1-beta(3e9236361fa97a9e6c685f4833ac457ae2d8c50a)go1.24.13, build downloadedgo1.27.0viaGOTOOLCHAIN=autoMinimal input
Created in
triage/gh-1015/repro/:a.ts: 5,000 lines ofexport const v{i}: number = "x";(produces 5,000 diagnostics)many/module_with_a_reasonably_long_name_{0000..1999}.ts: 2,000 tiny modulestsconfig.json:files: ["a.ts"]tsconfig.files.json:include: ["many/**/*.ts"]The helper
triage/gh-1015/repro.pyopens a pipe, togglesO_NONBLOCKon the write side, spawns a command, sleeps one second to let the buffer
fill, then drains stdout and reports size/count.
Commands run
Observed output (representative run after restoration of the uninstrumented
sys.rs):Verdict
REPRODUCED.
On a non-blocking stdout pipe, tsrs emits only a prefix of its output and
exits normally, while the pinned TypeScript Go compiler (
tsc-go) emitsthe full output with the same exit code. The Go-versus-Rust difference is
present on both the diagnostic listing and the
--listFilesOnlylisting.Diagnosis
First mismatching functions
Rust:
crates/tsrs_execute/src/sys.rs,impl System for OsSyslines 42–49(current
HEAD):Go:
triage/gh-1015/ts-ref/tsc/cmd/tsc/sys.go,osSyslines 47–67:where
newSystemsetswriter: os.Stdout(line 139).Semantic/control-flow difference
Go's
os.Stdout.Writeis backed by the Go runtime's poller: when theunderlying write returns
EAGAINon a non-blocking fd, the runtime parksthe goroutine until the fd becomes writable and retries the write.
Consequently
tsc-goblocks until the reader drains the pipe and thefull output is delivered.
Rust's
OsSysuses astd::io::BufWriter<std::io::Stdout>. Itswrite_allreturnsErr(ErrorKind::WouldBlock)as soon as the kernelreports
EAGAIN. The current helper only checks forBrokenPipe:Every non-
BrokenPipeerror, includingWouldBlock, is thereforesilently ignored. After the first blocked
write_all, theBufWriterkeeps the buffered bytes, but every subsequent flush also fails, so the
rest of the output is dropped while the program proceeds to its normal
exit.
Temporary instrumentation confirmed the exact error kind. With the
unmodified
sys.rsaugmented to log errant writes,tsrs --listFilesOnlyon a non-blocking pipe printed:and then produced a 65,536-byte stdout (the Linux pipe-buffer size).
The instrumentation change was reverted before this report was written.
Go-shaped fix approach
In
crates/tsrs_execute/src/sys.rs:ErrorKind::WouldBlock(and probablyErrorKind::Interrupted),do not discard the result.
POLLOUTusingrustix::poll::poll(already aworkspace dependency) and retry once the descriptor is writable.
(e.g.
BrokenPipe) occurs.exit_on_broken_pipebehaviour forBrokenPipe/EPIPEso thattsrs | headstill exits 141.This would be a small wrapper around the existing
BufWriterwrites,entirely within
tsrs_execute. A lighter alternative is to clearO_NONBLOCKat startup (as #830 explored), but that only matches thelauncher-protection scenario and still loses output if another process
switches the descriptor to non-blocking while tsrs is running.
Evidence and confidence
pipe-buffer limit for
--listFilesOnly, matching awrite(2)thatreturns
-EAGAIN.std::io::ErrorKind::WouldBlockfrom theBufWriterflush path.os.Stdoutwriter transparently polls onEAGAIN.Confidence: high.
Verification
Reporter's claim
The tsrs binary drops stdout once a non-blocking pipe buffer fills, exits
normally, and does not emit a stderr error. The pinned TypeScript Go compiler
(
tsc-go) prints all output under the same non-blocking pipe setup.Control comparison
Both compilers were run from the same working directory, using the same
tsconfig.jsonandtsconfig.files.json, the same--pretty false/--listFilesOnlyflags, and the same Python harness that delays the reader by one second.
target/debug/tsrsbuilt from this checkout:Version 7.1.0-beta (tsrs 7.1.0-beta.tsrs2, microsoft/TypeScript@3e9236361fa9)triage/gh-1015/ts-ref/tsc/tsc-gobuilt from the pinned tagv7.1-beta:Version 7.1.0-betaResult summary:
--listFilesOnly--listFilesOnly--listFilesOnly--listFilesOnlytsrs produces a complete, byte-identical output in blocking mode and matches
tsc-go. In non-blocking mode tsrs emits only a prefix—exactly the Linux
pipe-buffer size for
--listFilesOnly—and returns the same exit code. Nostderr message is produced in either tsrs run.
Verdict
bug. The checked-out tsrs diverges from the pinned TypeScript Go compiler
on a real control (blocking vs. non-blocking stdout pipe). The divergence is in
CLI/stdio behavior, which is part of the user-visible compiler contract modeled
by the Go implementation.
Confidence: high.
Fix
Changed behavior
After the fix, tsrs prints the complete
--listFilesOnlylisting and thefull set of diagnostics even when stdout is a non-blocking pipe. This matches
the pinned TypeScript Go compiler's behavior.
Go function followed
cmd/tsc/sys.go,osSys.Writer()returningos.Stdout. The Goruntime's poller transparently retries
EAGAIN/EINTRwrites to stdout.Implementation
crates/tsrs_execute/src/sys.rs:StdoutWriter, aWriteimpl aroundstd::io::Stdoutthat pollsstdout for
POLLOUTand retries onErrorKind::WouldBlockorInterrupted.BufWriter<std::io::Stdout>withBufWriter<StdoutWriter>inOsSys.crates/tsrs_cli/tests/integration/nonblocking_stdout.rs:tsrsbinary with stdouton a non-blocking pipe, delay the reader, and assert the complete output.
list_files_only_is_complete_on_a_non_blocking_stdoutfailed before thefix with a 65,536-byte truncated listing.
crates/tsrs_cli/tests/integration/main.rs:mod nonblocking_stdout;.tools/lint/unsafe_sites.tsv:poll_outunsafe site askeep.Verification commands and results
Build:
Reproduction harness (after fix):
Regression tests:
cargo test --profile dev --locked -p tsrs_cli --test integration -- broken_pipe nonblocking_stdout --test-threads=1Result:
test result: ok. 3 passed; 0 failed.Lints:
cargo clippy --all-targets --locked --config 'build.warnings="deny"' -p tsrs_cli -p tsrs_execute node tools/lint/source.mjsBoth pass.
Regression suite:
All 54
testdata/regressionscases pass.Final diff summary
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
I've opened a pull request with this fix: #1017