-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
cargo test will hang on windows, it may cause by thread_local drop? #7049
Comments
Thanks for this great report (and especially the reproductions)! Did you try this on Linux or MacOS as well? |
Yes, I have tested them on Linux and MacOS. None of the above tests will hang on Linux and MacOS. |
This is the one I find most interesting: #[test]
fn test_cargo_not_hang_1() {
use std::cell::LazyCell;
thread_local! {
pub static RUNTIME: LazyCell<tokio::runtime::Runtime> =
LazyCell::new(|| tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap());
}
let a = async { "1" };
let block = RUNTIME.with(|rt| rt.block_on(a));
println!("{:?}", block);
println!("999");
} I wonder if it's related to IO or task spawning? |
With your original example (that reproduces) on Linux I get the following:
|
why panic? I tried again and it was indeed a normal pass. No other code need |
I'm not sure either. It's morning and I haven't had enough caffeine yet, so I might have made a stupid mistake copying this over. |
Are you using master rather than 1.42? |
Yes. |
I tried It doesn't seem to be simple. These codes can't be reproduced. |
try spawn_blocking as well maybe? |
you are right, use #[test]
fn test_cargo_hang_2() {
use std::cell::LazyCell;
thread_local! {
pub static RUNTIME: LazyCell<tokio::runtime::Runtime> =
LazyCell::new(|| tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap());
}
let a = async {
tokio::task::spawn_blocking(|| { println!("234") });
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
"1"
};
let block = RUNTIME.with(|rt| rt.block_on(a));
println!("{:?}", block);
println!("999");
} output is:
and then hang forever |
Can you use a debugger to get a backtrace for each thread? |
Sorry, I work on a Linux platform and am unfamiliar with Windows. This problem happened when my project’s GitHub CI failed, so I opened an AWS cloud host to reproduce it. However, I have almost no experience with Windows platform tools. I try use windbg attach it(
I tried to find a friend(@zuoxinyu) to help me test it on his windows and use his windbg to display the symbol table information |
the full backtrace for all threads captured by windbg:
|
It's stuck on a call to I'm not so sure what to do about that. |
Version
Platform
os version:
Description
This is the simplest reproducible code, only on windows-msvc/windows-gnu toolchain:
cargo.toml
rust code
run with
it will output:
and then hang forever, it also hangs when this function use as the main fn
I suspect it's an issue in
thread_local
(maybe I should open an issue on rustc?).I also tried other ways to test, and the following tests will not hang:
The text was updated successfully, but these errors were encountered: