Skip to content
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

Open
driftluo opened this issue Dec 24, 2024 · 15 comments
Open

cargo test will hang on windows, it may cause by thread_local drop? #7049

driftluo opened this issue Dec 24, 2024 · 15 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-runtime Module: tokio/runtime

Comments

@driftluo
Copy link
Contributor

driftluo commented Dec 24, 2024

Version

C:\Users\Administrator\Desktop> cargo tree | grep tokio
│   │   ├── tokio v1.42.0
│   │   │   └── tokio-macros v2.4.0 (proc-macro)
│   │   ├── tokio-stream v0.1.17
│   │   │   └── tokio v1.42.0 (*)
│   └── tokio v1.42.0 (*)
│   │   ├── tokio v1.42.0 (*)
│   │   │   ├── tokio v1.42.0 (*)
│   │   │   │   ├── tokio v1.42.0 (*)
│   │   ├── tokio v1.42.0 (*)
│   │   ├── tokio-native-tls v0.3.1
│   │   │   └── tokio v1.42.0 (*)
│   ├── tokio v1.42.0 (*)
│   ├── tokio-native-tls v0.3.1 (*)
├── tokio v1.42.0 (*)
└── tokio-util v0.7.13
    └── tokio v1.42.0 (*)
    │   ├── tokio v1.42.0 (*)
    ├── tokio v1.42.0 (*)

Platform
os version:

C:\Users\Administrator\Desktop>ver

Microsoft Windows [Version 10.0.17763.2183]

C:\Users\Administrator\Desktop\ckb-sdk-rust>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows Server 2019 Datacenter
OS Version:                10.0.17763 N/A Build 17763
C:\Users\Administrator\Desktop>rustc --version --verbose
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1

Description

This is the simplest reproducible code, only on windows-msvc/windows-gnu toolchain:

cargo.toml

tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.12",  features = ["json"] }

rust code

#[test]
fn test_cargo_hang() {
    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 {
        reqwest::get("https://httpbin.org/ip")
            .await
            .unwrap()
            .json::<std::collections::HashMap<String, String>>()
            .await
    };
    let block = RUNTIME.with(|rt| rt.block_on(a));
    println!("{:?}", block);
    println!("999");
}

run with

$ cargo test --all-features -- test_cargo_hang --nocapture

it will output:

Ok({"origin": "103.142.141.72"})
999

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:

#[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");
}

#[test]
fn test_cargo_not_hang_2() {
    use std::sync::LazyLock;

    pub static RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| {
        tokio::runtime::Builder::new_current_thread()
            .enable_all()
            .build()
            .unwrap()
    });

    let a = async {
        reqwest::get("https://httpbin.org/ip")
            .await
            .unwrap()
            .json::<std::collections::HashMap<String, String>>()
            .await
    };
    let block = RUNTIME.block_on(a);
    println!("{:?}", block);
    println!("999");
}

#[test]
fn test_cargo_not_hang_3() {
    let a = async {
        reqwest::get("https://httpbin.org/ip")
            .await
            .unwrap()
            .json::<std::collections::HashMap<String, String>>()
            .await
    };
    let block = tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(a);
    println!("{:?}", block);
    println!("999");
}

#[test]
fn test_cargo_not_hang_4() {
    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(async{
              let listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
              loop {
                  let (socket, _) = listener.accept().await.unwrap();
              }
         });
       tokio::time::sleep(std::time::Duration::from_secs(2)).await;
       "1"
    };
    let block = RUNTIME.with(|rt| rt.block_on(a));
    println!("{:?}", block);
    println!("999");
}
@driftluo driftluo added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Dec 24, 2024
@driftluo driftluo changed the title cargo test will hang on windows msvc, it may cause by thread_local drop? cargo test will hang on windows, it may cause by thread_local drop? Dec 24, 2024
@Noah-Kennedy Noah-Kennedy added the M-runtime Module: tokio/runtime label Dec 24, 2024
@Noah-Kennedy
Copy link
Contributor

Thanks for this great report (and especially the reproductions)!

Did you try this on Linux or MacOS as well?

@driftluo
Copy link
Contributor Author

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.

@Noah-Kennedy
Copy link
Contributor

Noah-Kennedy commented Dec 24, 2024

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?

@Noah-Kennedy
Copy link
Contributor

With your original example (that reproduces) on Linux I get the following:

/usr/bin/cargo test --color=always --test rt_thread_local --all-features --profile test --no-fail-fast --config env.RUSTC_BOOTSTRAP=\"1\" --manifest-path /home/noah/RustroverProjects/tokio/tokio/Cargo.toml -- --format=json --exact -Z unstable-options --show-output
Testing started at 8:45 AM ...
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.19s
     Running tests/rt_thread_local.rs (target/debug/deps/rt_thread_local-140ce121b01ddf06)

there is no reactor running, must be called from the context of a Tokio 1.x runtime
thread 'test_cargo_hang' panicked at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/dns.rs:122:24:
there is no reactor running, must be called from the context of a Tokio 1.x runtime
stack backtrace:
   0: rust_begin_unwind
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/panicking.rs:74:14
   2: core::panicking::panic_display
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:264:5
   3: tokio::runtime::scheduler::Handle::current::panic_cold_display
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic.rs:100:13
   4: tokio::runtime::scheduler::Handle::current
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/scheduler/mod.rs:108:27
   5: tokio::runtime::handle::Handle::current
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/handle.rs:141:20
   6: tokio::runtime::blocking::pool::spawn_blocking
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/runtime/blocking/pool.rs:184:14
   7: tokio::task::blocking::spawn_blocking
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/task/blocking.rs:207:9
   8: <hyper_util::client::legacy::connect::dns::GaiResolver as tower_service::Service<hyper_util::client::legacy::connect::dns::Name>>::call
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/dns.rs:122:24
   9: <reqwest::dns::gai::GaiResolver as reqwest::dns::resolve::Resolve>::resolve
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/dns/gai.rs:26:18
  10: <reqwest::dns::resolve::DynResolver as tower_service::Service<hyper_util::client::legacy::connect::dns::Name>>::call
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/dns/resolve.rs:75:9
  11: <S as hyper_util::client::legacy::connect::dns::sealed::Resolve>::resolve
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/dns.rs:289:13
  12: hyper_util::client::legacy::connect::dns::resolve::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/dns.rs:299:5
  13: hyper_util::client::legacy::connect::http::HttpConnector<R>::call_async::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/http.rs:443:18
  14: <hyper_util::client::legacy::connect::http::HttpConnector<R> as tower_service::Service<http::uri::Uri>>::call::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/http.rs:376:62
  15: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
  16: <hyper_util::client::legacy::connect::http::HttpConnecting<R> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/connect/http.rs:526:9
  17: <hyper_tls::client::HttpsConnector<T> as tower_service::Service<http::uri::Uri>>::call::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-tls-0.6.0/src/client.rs:150:34
  18: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
  19: <hyper_tls::client::HttpsConnecting<T> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-tls-0.6.0/src/client.rs:179:9
  20: reqwest::connect::Connector::connect_with_maybe_proxy::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/connect.rs:299:41
  21: reqwest::connect::with_timeout::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/connect.rs:486:11
  22: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
  23: <hyper_util::service::oneshot::Oneshot<S,Req> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/service/oneshot.rs:55:38
  24: <F as futures_core::future::TryFuture>::try_poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-core-0.3.31/src/future.rs:92:9
  25: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/try_future/into_future.rs:34:9
  26: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  27: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  28: <futures_util::future::try_future::MapErr<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  29: <F as futures_core::future::TryFuture>::try_poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-core-0.3.31/src/future.rs:92:9
  30: <futures_util::future::try_future::into_future::IntoFuture<Fut> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/try_future/into_future.rs:34:9
  31: <futures_util::future::future::map::Map<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/map.rs:55:37
  32: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  33: <futures_util::future::try_future::MapOk<Fut,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  34: <F as futures_core::future::TryFuture>::try_poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-core-0.3.31/src/future.rs:92:9
  35: <futures_util::future::try_future::try_flatten::TryFlatten<Fut,<Fut as futures_core::future::TryFuture>::Ok> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/try_future/try_flatten.rs:49:61
  36: <futures_util::future::try_future::TryFlatten<Fut1,Fut2> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  37: <futures_util::future::try_future::AndThen<Fut1,Fut2,F> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/lib.rs:86:13
  38: <futures_util::future::either::Either<A,B> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/either.rs:108:32
  39: <hyper_util::common::lazy::Lazy<F,R> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/common/lazy.rs:71:28
  40: futures_util::future::future::FutureExt::poll_unpin
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/future/mod.rs:558:9
  41: <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.31/src/future/select.rs:118:35
  42: hyper_util::client::legacy::client::Client<C,B>::one_connection_for::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/client.rs:445:49
  43: hyper_util::client::legacy::client::Client<C,B>::connection_for::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/client.rs:396:61
  44: hyper_util::client::legacy::client::Client<C,B>::try_send_request::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/client.rs:280:14
  45: hyper_util::client::legacy::client::Client<C,B>::send_request::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/client.rs:248:70
  46: <hyper_util::client::legacy::client::ResponseFuture as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/hyper-util-0.1.10/src/client/legacy/client.rs:714:9
  47: <reqwest::async_impl::client::PendingRequest as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/async_impl/client.rs:2619:53
  48: <reqwest::async_impl::client::Pending as core::future::future::Future>::poll
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/async_impl/client.rs:2589:51
  49: reqwest::get::{{closure}}
             at /home/noah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/reqwest-0.12.9/src/lib.rs:310:48
  50: rt_thread_local::test_cargo_hang::{{closure}}
             at ./tests/rt_thread_local.rs:14:14
  51: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:123:9
  52: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
             at ./src/runtime/scheduler/current_thread/mod.rs:729:57
  53: tokio::runtime::coop::with_budget
             at ./src/runtime/coop.rs:107:5
  54: tokio::runtime::coop::budget
             at ./src/runtime/coop.rs:73:5
  55: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
             at ./src/runtime/scheduler/current_thread/mod.rs:729:25
  56: tokio::runtime::scheduler::current_thread::Context::enter
             at ./src/runtime/scheduler/current_thread/mod.rs:428:19
  57: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
             at ./src/runtime/scheduler/current_thread/mod.rs:728:36
  58: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
             at ./src/runtime/scheduler/current_thread/mod.rs:807:68
  59: tokio::runtime::context::scoped::Scoped<T>::set
             at ./src/runtime/context/scoped.rs:40:9
  60: tokio::runtime::context::set_scheduler::{{closure}}
             at ./src/runtime/context.rs:180:26
  61: std::thread::local::LocalKey<T>::try_with
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:283:12
  62: std::thread::local::LocalKey<T>::with
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:260:9
  63: tokio::runtime::context::set_scheduler
             at ./src/runtime/context.rs:180:9
  64: tokio::runtime::scheduler::current_thread::CoreGuard::enter
             at ./src/runtime/scheduler/current_thread/mod.rs:807:27
  65: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
             at ./src/runtime/scheduler/current_thread/mod.rs:716:19
  66: tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
             at ./src/runtime/scheduler/current_thread/mod.rs:196:28
  67: tokio::runtime::context::runtime::enter_runtime
             at ./src/runtime/context/runtime.rs:65:16
  68: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
             at ./src/runtime/scheduler/current_thread/mod.rs:184:9
  69: tokio::runtime::runtime::Runtime::block_on_inner
             at ./src/runtime/runtime.rs:368:47
  70: tokio::runtime::runtime::Runtime::block_on
             at ./src/runtime/runtime.rs:342:13
  71: rt_thread_local::test_cargo_hang::{{closure}}
             at ./tests/rt_thread_local.rs:19:35
  72: std::thread::local::LocalKey<T>::try_with
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:283:12
  73: std::thread::local::LocalKey<T>::with
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:260:9
  74: rt_thread_local::test_cargo_hang
             at ./tests/rt_thread_local.rs:19:17
  75: rt_thread_local::test_cargo_hang::{{closure}}
             at ./tests/rt_thread_local.rs:6:21
  76: core::ops::function::FnOnce::call_once
             at /home/noah/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  77: core::ops::function::FnOnce::call_once
             at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: test failed, to rerun pass `--test rt_thread_local`
error: 1 target failed:
    `--test rt_thread_local`

Process finished with exit code 101

@driftluo
Copy link
Contributor Author

driftluo commented Dec 24, 2024

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

@Noah-Kennedy
Copy link
Contributor

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.

@ChrisDenton
Copy link

ChrisDenton commented Dec 24, 2024

Are you using master rather than 1.42?

@Noah-Kennedy
Copy link
Contributor

Yes.

@driftluo
Copy link
Contributor Author

driftluo commented Dec 24, 2024

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?

I tried test_cargo_not_hang_4(), which uses Tcp listener + spawn + time::sleep modules, but it didn’t hang.

It doesn't seem to be simple. These codes can't be reproduced.

@Noah-Kennedy
Copy link
Contributor

try spawn_blocking as well maybe?

@driftluo
Copy link
Contributor Author

try spawn_blocking as well maybe?

you are right, use spawn_blocking will cause hang forever. code is:

#[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:

234
"1"
999

and then hang forever

@Darksonn
Copy link
Contributor

Can you use a debugger to get a backtrace for each thread?

@driftluo
Copy link
Contributor Author

driftluo commented Dec 30, 2024

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(a.exe is test_cargo_hang_2 use as main fn):


Microsoft (R) Windows Debugger Version 10.0.20348.1 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\Users\luoc\Desktop\a\target\debug\a.exe

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00007ff6`42880000 00007ff6`43777000   image00007ff6`42880000
ModLoad: 00007ffb`ac110000 00007ffb`ac305000   ntdll.dll
ModLoad: 00007ffb`aaaa0000 00007ffb`aab5e000   C:\Windows\System32\KERNEL32.DLL
ModLoad: 00007ffb`a99a0000 00007ffb`a9c69000   C:\Windows\System32\KERNELBASE.dll
ModLoad: 00007ffb`ab390000 00007ffb`ab3fb000   C:\Windows\System32\ws2_32.dll
ModLoad: 00007ffb`aa260000 00007ffb`aa38a000   C:\Windows\System32\RPCRT4.dll
ModLoad: 00007ffb`a96f0000 00007ffb`a971e000   C:\Windows\SYSTEM32\userenv.dll
ModLoad: 00007ffb`a9fc0000 00007ffb`aa0c0000   C:\Windows\System32\ucrtbase.dll
ModLoad: 00007ffb`a9ee0000 00007ffb`a9f63000   C:\Windows\System32\bcryptprimitives.dll
ModLoad: 00007ffb`aa6a0000 00007ffb`aa73e000   C:\Windows\System32\msvcrt.dll
(15c0.1eb4): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ffb`ac1e06b0 cc              int     3
0:000> ~* kv

.  0  Id: 15c0.1eb4 Suspend: 1 Teb: 00000012`85b62000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 00000012`85dff310 00007ffb`ac1e3ba2     : 00000000`00000000 00007ffb`ac241a90 00007ffb`ac241a90 00007ffb`ac241a90 : ntdll!LdrpDoDebuggerBreak+0x30
01 00000012`85dff350 00007ffb`ac184cdb     : 00000000`00000001 00000000`00000000 00000000`00000000 00000000`00000001 : ntdll!LdrpInitializeProcess+0x1f42
02 00000012`85dff780 00007ffb`ac184b63     : 00000000`00000000 00007ffb`ac110000 00000000`00000000 00000012`85b62000 : ntdll!LdrpInitialize+0x15f
03 00000012`85dff820 00007ffb`ac184b0e     : 00000012`85dff8a0 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!LdrpInitialize+0x3b
04 00000012`85dff850 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!LdrInitializeThunk+0xe

   1  Id: 15c0.940 Suspend: 1 Teb: 00000012`85b64000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 00000012`85fff4e8 00007ffb`ac162dc7     : 00000000`00000000 00000000`00000000 00000128`f08b33b0 00000128`f08b5690 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 00000012`85fff4f0 00007ffb`aaab7034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!TppWorkerThread+0x2f7
02 00000012`85fff7f0 00007ffb`ac162651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
03 00000012`85fff820 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21

   2  Id: 15c0.1798 Suspend: 1 Teb: 00000012`85b66000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 00000012`861ffa28 00007ffb`ac162dc7     : 00000000`00000000 00000000`00000000 00000128`f08b33b0 00000128`f08b6980 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 00000012`861ffa30 00007ffb`aaab7034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!TppWorkerThread+0x2f7
02 00000012`861ffd30 00007ffb`ac162651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
03 00000012`861ffd60 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21

   3  Id: 15c0.2614 Suspend: 1 Teb: 00000012`85b68000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 00000012`863ff7a8 00007ffb`ac162dc7     : 00000000`00000000 00000000`00000000 00000128`f08b33b0 00000128`f08b6fe0 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 00000012`863ff7b0 00007ffb`aaab7034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!TppWorkerThread+0x2f7
02 00000012`863ffab0 00007ffb`ac162651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
03 00000012`863ffae0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21

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
image
image

@zuoxinyu
Copy link

the full backtrace for all threads captured by windbg:

.  0  Id: 5cfc.2690 Suspend: 1 Teb: 000000e0`60b07000 Unfrozen "main"
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`60cfec58 00007ffb`16129cee     : 000000e0`60cfecf0 00007ff7`5102ae3c 00000000`00000002 00000000`00000006 : ntdll!ZwWaitForSingleObject+0x14
01 000000e0`60cfec60 00007ff7`51057c51     : 000000e0`60cfee00 000000e0`60cff000 000000e0`00000000 00000000`000000d4 : KERNELBASE!WaitForSingleObjectEx+0x8e
02 000000e0`60cfed00 00007ff7`5102ab93     : 000000e0`60cfedc0 00007ff7`50fffc04 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!std::sys::pal::windows::thread::Thread::join+0x21 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\pal\windows\thread.rs @ 80] 
03 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::thread::JoinInner::join+0x10 (Inline Function @ 00007ff7`5102ab93) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\thread\mod.rs @ 1634] 
04 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::thread::JoinHandle::join+0x10 (Inline Function @ 00007ff7`5102ab93) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\thread\mod.rs @ 1780] 
05 000000e0`60cfed90 00007ff7`5100885c     : 000000e0`60cfee00 00000000`00000001 0000020e`743872b0 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!test::run_tests::RunningTest::join+0x33 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/test\src\lib.rs @ 276] 
06 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!test::run_tests+0x2143 (Inline Function @ 00007ff7`5100885c) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/test\src\lib.rs @ 437] 
07 000000e0`60cfee00 00007ff7`510296a3     : 00000000`0000000f 0000020e`74370000 0000020e`743702e8 0000020e`743829b0 : tokio_test_cd0e2fcaa58ccefc!test::console::run_tests_console+0x282c [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/test\src\console.rs @ 322] 
08 000000e0`60cff750 00007ff7`5102aac3     : 00007ffb`16167db0 00007ff7`51090be1 0000020e`00000000 0000020e`74470fc0 : tokio_test_cd0e2fcaa58ccefc!test::test_main+0x163 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/test\src\lib.rs @ 140] 
09 000000e0`60cffb10 00007ff7`50f675f5     : 00000000`00000038 0000020e`00000000 000000e0`60cffc90 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!test::test_main_static+0x63 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/test\src\lib.rs @ 161] 
0a 000000e0`60cffbc0 00007ff7`50f644bb     : 00000000`00000000 00000000`00000000 00007ffb`17540000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!tokio_test::main+0x15 [C:\Users\Admin\test\tokio-test\src\main.rs @ 1] 
0b 000000e0`60cffbf0 00007ff7`50f6762e     : 00007ffb`17540000 00000000`00000000 00007ffb`00000000 00007ff7`51058c84 : tokio_test_cd0e2fcaa58ccefc!core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >+0xb [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs @ 250] 
0c (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!core::hint::black_box (Inline Function @ 00007ff7`50f6762e) [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs @ 389] 
0d 000000e0`60cffc30 00007ff7`50f664e1     : 00000000`00000001 00000000`00000008 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!std::sys::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >+0xe [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\backtrace.rs @ 157] 
0e 000000e0`60cffc70 00007ff7`5104020c     : 00000000`00000000 00000000`00000038 000000e0`60cffe18 00007ffb`16780000 : tokio_test_cd0e2fcaa58ccefc!std::rt::lang_start::closure$0<tuple$<> >+0x11 [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs @ 195] 
0f (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::rt::lang_start_internal::closure$1+0x6 (Inline Function @ 00007ff7`5104020c) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs @ 174] 
10 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::panicking::try::do_call+0x6 (Inline Function @ 00007ff7`5104020c) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs @ 557] 
11 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::panicking::try+0x6 (Inline Function @ 00007ff7`5104020c) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs @ 520] 
12 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::panic::catch_unwind+0x6 (Inline Function @ 00007ff7`5104020c) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panic.rs @ 358] 
13 000000e0`60cffcb0 00007ff7`50f664ba     : 00000000`00000000 00007ffb`16790475 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!std::rt::lang_start_internal+0x21c [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs @ 174] 
14 000000e0`60cffde0 00007ff7`50f67619     : 00000000`00000007 00000000`00000000 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!std::rt::lang_start<tuple$<> >+0x3a [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs @ 194] 
15 000000e0`60cffe50 00007ff7`5106d6ec     : 00000000`00000000 00007ff7`5106d765 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!main+0x19
16 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!invoke_main+0x22 (Inline Function @ 00007ff7`5106d6ec) [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 78] 
17 000000e0`60cffe80 00007ffb`1755259d     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : tokio_test_cd0e2fcaa58ccefc!__scrt_common_main_seh+0x10c [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
18 000000e0`60cffec0 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x1d
19 000000e0`60cffef0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

   1  Id: 5cfc.1508 Suspend: 1 Teb: 000000e0`60b09000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`60dffab8 00007ffb`18c8586e     : 00000000`0001000a 0000020e`7437b701 00000000`00000001 0000020e`7437b760 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 000000e0`60dffac0 00007ffb`1755259d     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlClearThreadWorkOnBehalfTicket+0x35e
02 000000e0`60dffda0 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x1d
03 000000e0`60dffdd0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

   2  Id: 5cfc.1e80 Suspend: 1 Teb: 000000e0`60b0b000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`60effb28 00007ffb`18c8586e     : 0000020e`7437b760 0000020e`7437b760 00000000`00000001 0000020e`74382600 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 000000e0`60effb30 00007ffb`1755259d     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlClearThreadWorkOnBehalfTicket+0x35e
02 000000e0`60effe10 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x1d
03 000000e0`60effe40 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

   3  Id: 5cfc.4a64 Suspend: 1 Teb: 000000e0`60b0d000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`60fffac8 00007ffb`18c8586e     : 0000020e`7437b760 0000020e`7437b760 00000000`00000001 00000000`00000000 : ntdll!NtWaitForWorkViaWorkerFactory+0x14
01 000000e0`60fffad0 00007ffb`1755259d     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlClearThreadWorkOnBehalfTicket+0x35e
02 000000e0`60fffdb0 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x1d
03 000000e0`60fffde0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

   4  Id: 5cfc.5e74 Suspend: 1 Teb: 000000e0`60b0f000 Unfrozen "test_cargo_hang_2"
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`611ff308 00007ffb`16129cee     : 00000000`00000001 00000000`00000000 0001020e`74398f74 0000020e`74398f70 : ntdll!ZwWaitForSingleObject+0x14
01 000000e0`611ff310 00007ff7`51057c51     : 00000000`7ffe0385 000000e0`611ff470 0000020e`00000000 00000000`000000d8 : KERNELBASE!WaitForSingleObjectEx+0x8e
02 000000e0`611ff3b0 00007ff7`50fb3125     : 0000020e`74398ef0 0000020e`74398f70 0000020e`74398f80 0000020e`74398f70 : tokio_test_cd0e2fcaa58ccefc!std::sys::pal::windows::thread::Thread::join+0x21 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\pal\windows\thread.rs @ 80] 
03 000000e0`611ff440 00007ff7`50fb32cf     : 00000000`00000001 0000020e`74398f70 00000000`00000003 00000000`00000002 : tokio_test_cd0e2fcaa58ccefc!std::thread::JoinInner<tuple$<> >::join<tuple$<> >+0x25 [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\mod.rs @ 1634] 
04 000000e0`611ff520 00007ff7`50faad1e     : 000000e0`611ff710 00000000`00000000 00000000`00000000 0000020e`743820c0 : tokio_test_cd0e2fcaa58ccefc!std::thread::JoinHandle<tuple$<> >::join<tuple$<> >+0x1f [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\mod.rs @ 1781] 
05 000000e0`611ff560 00007ff7`50faaf00     : 000000e0`611ff7f8 00007ff7`50fb9816 000000e0`611ffa90 00007ff7`50f78692 : tokio_test_cd0e2fcaa58ccefc!tokio::runtime::blocking::pool::BlockingPool::shutdown+0x2ae [C:\Users\Admin\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-2eab394af869c8a2\tokio-1.42.0\src\runtime\blocking\pool.rs @ 276] 
06 000000e0`611ff7b0 00007ff7`50f7902f     : 000000e0`611ffa60 000000e0`611ffa88 000000e0`611ffa88 00007ff7`50f781ae : tokio_test_cd0e2fcaa58ccefc!tokio::runtime::blocking::pool::impl$4::drop+0x20 [C:\Users\Admin\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-2eab394af869c8a2\tokio-1.42.0\src\runtime\blocking\pool.rs @ 285] 
07 000000e0`611ff7f0 00007ff7`50f78518     : 00000000`00000002 00000000`00000006 00000000`00000000 0000020e`74370150 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<tokio::runtime::blocking::pool::BlockingPool>+0x1f [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
08 000000e0`611ff840 00007ff7`50f64742     : 0000020e`74370000 00000000`00000014 0000020e`743872e0 0000020e`743872d8 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<tokio::runtime::runtime::Runtime>+0x48 [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
09 000000e0`611ff890 00007ff7`50f6478e     : 0000020e`743872d0 00000000`00000000 00000000`00000014 00000000`00000014 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<enum2$<core::cell::lazy::State<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> > >+0x32 [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
0a 000000e0`611ff8d0 00007ff7`50f64aee     : 00000000`00000001 00000000`00000019 000000e0`3b9aca00 00000000`00000014 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<core::cell::UnsafeCell<enum2$<core::cell::lazy::State<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> > > >+0xe [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
0b 000000e0`611ff900 00007ff7`50f64772     : 0000020e`74388728 00000000`00000008 00007ff7`51072a70 0000020e`74388728 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<core::cell::lazy::LazyCell<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> >+0xe [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
0c 000000e0`611ff930 00007ff7`50f69fec     : 00000000`00000009 00007ffb`18c9472a 00000000`00000003 0000020e`74388788 : tokio_test_cd0e2fcaa58ccefc!core::ptr::drop_in_place<enum2$<std::sys::thread_local::native::lazy::State<core::cell::lazy::LazyCell<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()>,tuple$<> > > >+0x22 [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs @ 574] 
0d 000000e0`611ff970 00007ff7`50f69a9b     : 0000020e`743872e0 00007ffb`14000014 0000020e`743872d0 0000020e`74370000 : tokio_test_cd0e2fcaa58ccefc!std::sys::thread_local::native::lazy::destroy::closure$0<core::cell::lazy::LazyCell<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> >+0x9c [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\thread_local\native\lazy.rs @ 99] 
0e 000000e0`611ffad0 00007ff7`50f69f1f     : 0000020e`74370000 0000020e`7437de4f 00000000`00000000 0000020e`7437de50 : tokio_test_cd0e2fcaa58ccefc!std::sys::thread_local::abort_on_dtor_unwind<std::sys::thread_local::native::lazy::destroy::closure_env$0<core::cell::lazy::LazyCell<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> > >+0x1b [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\thread_local\mod.rs @ 182] 
0f 000000e0`611ffb20 00007ff7`5105a068     : 00000000`00000000 00000000`00000000 00000000`00000003 00000000`00000004 : tokio_test_cd0e2fcaa58ccefc!std::sys::thread_local::native::lazy::destroy<core::cell::lazy::LazyCell<tokio::runtime::runtime::Runtime,tokio::runtime::runtime::Runtime (*)()> >+0x1f [C:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\thread_local\native\lazy.rs @ 93] 
10 (Inline Function) --------`--------     : --------`-------- --------`-------- --------`-------- --------`-------- : tokio_test_cd0e2fcaa58ccefc!std::sys::thread_local::destructors::list::run+0x88 (Inline Function @ 00007ff7`5105a068) [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\thread_local\destructors\list.rs @ 34] 
11 000000e0`611ffb60 00007ffb`18ccc10a     : 00000000`7ffe0384 00007ffa`c87154e6 00000000`00000000 00007ffb`1613218d : tokio_test_cd0e2fcaa58ccefc!std::sys::thread_local::guard::windows::tls_callback+0xa8 [/rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\thread_local\guard\windows.rs @ 85] 
12 000000e0`611ffbb0 00007ffb`18c78b8f     : 00000000`00000000 00007ffb`160f0000 00000000`7ffe0384 00007ffb`1613201d : ntdll!RtlGetCurrentDirectory_U+0x49a
13 000000e0`611ffbe0 00007ffb`18c79819     : 00007ff7`510724f0 00007ff7`50f60000 000000e0`00000003 0000020e`743752f0 : ntdll!RtlActivateActivationContextUnsafeFast+0x12f
14 000000e0`611ffc50 00007ffb`18c79458     : 000000e0`60b0f000 0000020e`74375150 00007ff7`51059fc0 000000e0`60b107ee : ntdll!LdrShutdownThread+0x5b9
15 000000e0`611ffcc0 00007ffb`18caafae     : 0000020e`74387c00 000000e0`60b06000 00000000`00000000 00000000`00000000 : ntdll!LdrShutdownThread+0x1f8
16 000000e0`611ffdc0 00007ffb`175525a6     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlExitUserThread+0x3e
17 000000e0`611ffe00 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x26
18 000000e0`611ffe30 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

   5  Id: 5cfc.2c40 Suspend: 1 Teb: 000000e0`60b11000 Unfrozen "tokio-runtime-worker"
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`613ff628 00007ffb`18c7a4fe     : 0000020e`00000000 00000000`00000013 00007ffb`18dd6350 00000000`00000000 : ntdll!ZwWaitForSingleObject+0x14
01 000000e0`613ff630 00007ffb`18c79302     : 000000e0`60b11000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!LdrGetDllHandleEx+0x35e
02 000000e0`613ff670 00007ffb`18caafae     : 0000020e`74387500 000000e0`60b06000 00000000`00000000 00000000`00000000 : ntdll!LdrShutdownThread+0xa2
03 000000e0`613ff770 00007ffb`175525a6     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlExitUserThread+0x3e
04 000000e0`613ff7b0 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x26
05 000000e0`613ff7e0 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

#  6  Id: 5cfc.4f00 Suspend: 1 Teb: 000000e0`60b13000 Unfrozen
 # Child-SP          RetAddr               : Args to Child                                                           : Call Site
00 000000e0`614ffdc8 00007ffb`18d2735e     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!DbgBreakPoint
01 000000e0`614ffdd0 00007ffb`1755259d     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!DbgUiRemoteBreakin+0x4e
02 000000e0`614ffe00 00007ffb`18caaf38     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x1d
03 000000e0`614ffe30 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x28

@Darksonn
Copy link
Contributor

Darksonn commented Jan 1, 2025

It's stuck on a call to std::thread::JoinHandle::join ... I guess the thread is probably awaiting shutdown of itself in the tls storage.

I'm not so sure what to do about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-runtime Module: tokio/runtime
Projects
None yet
Development

No branches or pull requests

5 participants