Skip to content

Audit forced exits that can truncate piped output #179

Description

@myobie

process.exit() terminates before Node drains asynchronous stdout or stderr. A command that writes and then forces an exit can truncate under a pipe or output capture.

The shipped pty completions command demonstrated the failure. A conformance suite found it before a user report: the command returned success with truncated output, and no error identified the loss.

The production source has 152 remaining process.exit() sites. Of these, 146 can follow output written by this process:

  • 125 stderr exits follow error text.
  • Three stdout exits follow usage text.
  • Two exits follow interactive prompts.
  • Eight local or remote attach and peek callbacks can follow streamed terminal output.
  • One client fallback can follow attach output.
  • One stdio remote-control exit can follow protocol output.
  • Four TUI exits follow terminal restoration writes.
  • Two event signal handlers can follow event output.

The 125 stderr sites are important because redirection is common during diagnosis. The command can preserve its nonzero status while losing the message that explains it.

The known fix shape is small: set process.exitCode and return, which lets Node finish pending writes. The groups need separate scope decisions because usage, errors, streams, protocols, and terminal restoration have different risks.

The deterministic reproduction in PR #178 delays every stdout write. The old forced-exit path produces empty output; the natural-exit path produces the complete checked-in artifact. Any broader change needs an equivalent failing control before it changes behavior.

Activity

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