-
Notifications
You must be signed in to change notification settings - Fork 341
Not joining all threads = memory leaked on process exit #759
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
Comments
Thank you for the report, two asks |
I just realize, that this does not happen in #757 either, so no need to test this. Shutting down the threads could be possibly added to the macros, but it would have to be a manual call for other use cases, as we create a global runtime, and so do not get the benefit of using |
Yes, #757 does not solve the leak. I created a repository to easily test this and to see some differences: https://github.com/faern/leakruntime. This repository currently points to the One interesting thing I noted is that while cargo +1.39.0 valgrind --test tokio --features tokio; do true; done async-std on the other hand leak many objects both from |
Yes the difference in what the macros expand to is shown in the |
The very rare leak found in #[test]
fn just_sleep() {
std::thread::sleep(std::time::Duration::from_millis(1));
} So that one can't be blamed on tokio. One just have to run it sufficiently many times to hit it. I think I will report that directly to Rust. But it's unrelated to all the leaks this issue is about. |
async-std spawns global runtime threads for executors, timers and potentially IO in the background which will simply run forever. So the leak seems kind of by design. |
Since it's possible to interact with the global runtime via for example I get that there are a lot of users who don't care about this, and the OS will clean up stuff as the process exits anyway. So it's up to you if you prioritize this at all. I just wanted to report my findings. |
I seem to have the same issue, but I didn't have it in v1.5.0. It only shows up in v1.6.2. FWIW, also happens if I set |
Hi. I'm implementing a library at a low level which allocates and frees memory manually. To try to keep it correct I run example binaries and tests under Valgrind a lot. However, when using
async-std
my programs and tests very often seem to not correctly join threads before exiting, resulting in leaks that make Valgrind sad and my automated tests fail. I experience this on Linux and have not tried it elsewhere.A simple failing test. Placed under
tests/all_tests.rs
:You can run it under vanilla Valgrind with
valgrind --leak-check=full ./target/debug/whatever_the_filename_is
. Butcargo valgrind
has prettier output. Due to the racy nature of this it might not always fail, but for me it does ~90% of the runs:A very similar leak stack trace can be obtained from the following test:
Which is fixed by joining all threads before exiting:
This leads me to suspect the
#[async_std::main]
and#[async_std::test]
macros don't properly join all threads before exiting.The text was updated successfully, but these errors were encountered: