Skip to content

Severe memory leak in Rustc #78125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Davester47 opened this issue Oct 20, 2020 · 9 comments
Closed

Severe memory leak in Rustc #78125

Davester47 opened this issue Oct 20, 2020 · 9 comments
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Davester47
Copy link

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.

@Davester47 Davester47 added the C-bug Category: This is a bug. label Oct 20, 2020
@rustbot rustbot added the I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. label Oct 20, 2020
@camelid camelid added I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 20, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 20, 2020

This looks like a duplicate of #75992.

@camelid
Copy link
Member

camelid commented Oct 20, 2020

@Davester47 can you check if this issue occurs on Rust 1.45?

@Davester47
Copy link
Author

Alright, I'm installing 1.45.0 to check it

@Davester47
Copy link
Author

1.45.0 successfully compiled it.

@camelid
Copy link
Member

camelid commented Oct 20, 2020

Probably a duplicate of #75992 as @jyn514 suggested.

@camelid camelid closed this as completed Oct 20, 2020
@camelid camelid removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 20, 2020
@Davester47
Copy link
Author

1.46.0 has the leak as well

@Davester47
Copy link
Author

Should I just be using 1.45.0 from now on? It doesn't look like any progress is being made on #75992. I noticed in #77628 that the offending code was let mut cursor = self.collection.find(None, None).await? I just confirmed that it compiles fine without this line for me as well.

@jyn514
Copy link
Member

jyn514 commented Oct 20, 2020

@Davester47 if you can come up with an MCVE for the hang, that would be extremely helpful. Right now all the examples we have require actix.

@Davester47
Copy link
Author

Alright, I'll give it a shot in the next couple days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants