Skip to content

Cargo keeps entire rustc/rustdoc stdout in memory  #6197

@Aaron1011

Description

@Aaron1011

Problem

When cargo invokes rustc or rustdoc (via cargo doc or cargo build, the child process's entire stdout is kept in memory. This can lead to the system's memory being completely exhausted if rustc or rustdoc produce a lot of output (e.g. when RUST_LOG is set).

Steps

  1. Create a file called yes.sh containing the string yes (If the yes program is unavailable, replace it with a script that endlessly writes to stdout)
  2. Run chmod +x ./yes.sh
  3. Run RUSTC=./yes.sh cargo build in any crate directory.
  4. Observe that cargo's memory usage quickly rises to consume all available memory.

Possible Solution(s)

cargo should clear each line of a child command's stdout from memory once it has been printed, since it won't be needed again.

Notes

Output of cargo version: cargo 1.29.0 (524a578d7 2018-08-05)
Tested on Arch Linux - this should be reproducible on any Linux-based system.

Metadata

Metadata

Assignees

Labels

A-console-outputArea: Terminal output, colors, progress bar, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions