Skip to content

Output piped to another command is cut off after 64 KiB #228

Open

Description

@lodgekeeper

When stdout is a pipe, Node writes to it asynchronously, and run() calls process.exit() as soon as the result has been logged. Whatever the pipe has not yet taken is lost, so a command whose output is larger than the pipe's buffer (64 KiB on Linux) is cut off, silently and with exit code 0. That includes the README's setup for piping into jq:

import { createCli, lineByLineConsoleLogger, os } from "trpc-cli";

const router = os.router({ big: os.handler(() => "x".repeat(1_000_000)) });
await createCli({ router }).run({ logger: lineByLineConsoleLogger });
$ node cli.mjs big | wc -c
131072
$ node cli.mjs big | (sleep 1; wc -c)
65536

The whole output is 1,000,001 bytes. This is trpc-cli 0.17.1 on Node 26.12, Linux. Node's docs for process.exit() describe the cause: "writes to process.stdout in Node.js are sometimes asynchronous and may occur over multiple ticks of the Node.js event loop".

Errors are cut off the same way, since run() logs the error and then exits: a command that throws an Error with a 1,000,000-character message, its stderr piped through (sleep 1; wc -c), delivers 65,536 bytes.

Exiting once the streams have drained fixes it. With the documented process.exit override below, all 1,000,001 bytes arrive; run() could do the same for stdout and stderr before it exits.

process: { exit: (code) => process.stdout.write("", () => process.exit(code)) }

Activity

  1. pullfrog commented on Oct 23, 2026

    @pullfrog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions