Skip to content

Severe memory leak in Rustc #78125

@Davester47

Description

@Davester47

AFAICT, this isn't a security vulnerability, so I'm reporting this here.

I was attempting to build a RESTful CRUD API with Actix-web, and I've stumbled into a compiler bug. All the source files are about 150-200 LoC, so I'm not going to post them all here. The code that reproduces this bug is available at https://github.com/Davester47/rustc-leak. I left instructions to reproduce the leak in the README.md

To Reproduce:

When I try to compile it with cargo build, it compiles all the dependencies fine. However, as soon as it gets to building the final binary ("snack-actix"), it starts leaking memory like crazy (500+ MB/s) and it never stops. It ran for over 10 minutes on the final phase on my Windows laptop, and I think it used over 15 GB of swap (I can't tell for sure on the task manager). On linux, the computer becomes unusable as soon as it starts using swap space.

My advice if you try to reproduce this is to have Task Manager or htop open while you compile it, and be ready to hit Ctrl+C. It will use all of your memory if you don't.

The last thing that I did before it started leaking memory was finish the function in src/controllers/snack.rs. I know that my code is probably bad style or not idiomatic or something, but it shouldn't use over 12 GBs of memory.

I don't know how I would find where the leak happens or why it happens, so I'm hoping someone here will be able to. Let me know if you need more information. Please don't let this issue get sidelined.

Meta

I've confirmed that the leak occurs on all of the following toolchains.

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

rustc 1.49.0-nightly (b1496c6e6 2020-10-18)
binary: rustc
commit-hash: b1496c6e606dd908dd651ac2cce89815e10d7fc5
commit-date: 2020-10-18
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-pc-windows-gnu
release: 1.47.0
LLVM version: 11.0

There's no backtrace, since I had to kill rustc with Ctrl+C every time to avoid crashing my computer (Sometimes I failed). I have 8 GBs of RAM, which should be enough to compile anything. It never panicked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitC-bugCategory: This is a bug.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions