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

Tokio 1.36.0, panic SHUTDOWN.unpack(current) == 0 || matches!(tick, Tick :: Clear(_)) when using tokio::net::windows::named_pipe #6365

Closed
fufesou opened this issue Feb 23, 2024 · 11 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. M-net Module: tokio/net

Comments

@fufesou
Copy link

fufesou commented Feb 23, 2024

Description

Version
1.36.0

Platform
64-bit (Windows)

Description

I'm using tokio::net::windows::named_pipe to process ipc.

It was ok for tokio 1.28.

I'm facing panic with tokio 1.33 and 1.36.

Example

I tried this code:

use std::io;
use tokio::net::windows::named_pipe::*;

const PIPE_NAME: &str = r"\\.\pipe\MyTestApp\query";

fn create_server(path: &str, first: bool) -> io::Result<NamedPipeServer> {
    ServerOptions::new()
        .access_inbound(true)
        .access_outbound(true)
        .out_buffer_size(65536)
        .in_buffer_size(65536)
        .first_pipe_instance(first)
        .create(path)
}

#[tokio::main(flavor = "current_thread")]
pub async fn start_server() {
    let mut server = create_server(PIPE_NAME, true).unwrap();
    loop {
        server.connect().await.unwrap();
        let new_listener = create_server(PIPE_NAME, false).unwrap();
        let _conn = std::mem::replace(&mut server, new_listener);
        // spawn a new task to handle the _conn
    }
}

async fn test_conn() {
    let _ = ClientOptions::new()
        .read(true)
        .write(true)
        .open(PIPE_NAME)
        .unwrap();
}

#[tokio::main]
async fn main() {
    std::thread::spawn(move || {
        start_server();
    });

    tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    test_conn().await;
    loop {
        tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
    }
}

logs

thread '<unnamed>' panicked at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\io\scheduled_io.rs:214:9:
assertion failed: SHUTDOWN.unpack(current) == 0 || matches!(tick, Tick :: Clear(_))
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:72
   2: core::panicking::panic
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:127
   3: tokio::runtime::io::scheduled_io::ScheduledIo::set_readiness<tokio::runtime::io::driver::impl$0::turn::closure_env$0>
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\io\scheduled_io.rs:214
   4: tokio::runtime::io::driver::Driver::turn
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\io\driver.rs:180
   5: tokio::runtime::io::driver::Driver::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\io\driver.rs:122
   6: enum2$<tokio::runtime::driver::IoStack>::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\driver.rs:173 
   7: tokio::runtime::time::Driver::park_internal
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\time\mod.rs:207
   8: tokio::runtime::time::Driver::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\time\mod.rs:148
   9: enum2$<tokio::runtime::driver::TimeDriver>::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\driver.rs:329 
  10: tokio::runtime::driver::Driver::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\driver.rs:69  
  11: tokio::runtime::scheduler::current_thread::impl$3::park::closure$1
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:366
  12: tokio::runtime::scheduler::current_thread::Context::enter<tuple$<>,tokio::runtime::scheduler::current_thread::impl$3::park::closure_env$1>
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:404
  13: tokio::runtime::scheduler::current_thread::Context::park
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:365
  14: tokio::runtime::scheduler::current_thread::impl$8::block_on::closure$0<core::pin::Pin<ref_mut$<enum2$<test_tokio::start_server::async_block_env$0> > > >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:687
  15: tokio::runtime::scheduler::current_thread::impl$8::enter::closure$0<tokio::runtime::scheduler::current_thread::impl$8::block_on::closure_env$0<core::pin::Pin<ref_mut$<enum2$<test_tokio::start_server::async_block_env$0> > > >,enum2$<core::option::Option<tu
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:737
  16: tokio::runtime::context::scoped::Scoped<enum2$<tokio::runtime::scheduler::Context> >::set<enum2$<tokio::runtime::scheduler::Context>,tokio::runtime::scheduler::current_thread::impl$8::enter::closure_env$0<tokio::runtime::scheduler::current_thread::impl$8:
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\context\scoped.rs:40
  17: tokio::runtime::context::set_scheduler::closure$0<tuple$<alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core,alloc::alloc::Global>,enum2$<core::option::Option<tuple$<> > > >,tokio::runtime::scheduler::current_thread::impl$8::enter::closure_e
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\context.rs:176
  18: std::thread::local::LocalKey<tokio::runtime::context::Context>::try_with<tokio::runtime::context::Context,tokio::runtime::context::set_scheduler::closure_env$0<tuple$<alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core,alloc::alloc::Global>,
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\std\src\thread\local.rs:270
  19: std::thread::local::LocalKey<tokio::runtime::context::Context>::with<tokio::runtime::context::Context,tokio::runtime::context::set_scheduler::closure_env$0<tuple$<alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core,alloc::alloc::Global>,enum
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\std\src\thread\local.rs:246
  20: tokio::runtime::context::set_scheduler<tuple$<alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core,alloc::alloc::Global>,enum2$<core::option::Option<tuple$<> > > >,tokio::runtime::scheduler::current_thread::impl$8::enter::closure_env$0<tokio:
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\context.rs:176
  21: tokio::runtime::scheduler::current_thread::CoreGuard::enter<tokio::runtime::scheduler::current_thread::impl$8::block_on::closure_env$0<core::pin::Pin<ref_mut$<enum2$<test_tokio::start_server::async_block_env$0> > > >,enum2$<core::option::Option<tuple$<> >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:737
  22: tokio::runtime::scheduler::current_thread::CoreGuard::block_on<core::pin::Pin<ref_mut$<enum2$<test_tokio::start_server::async_block_env$0> > > >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:646
  23: tokio::runtime::scheduler::current_thread::impl$0::block_on::closure$0<enum2$<test_tokio::start_server::async_block_env$0> >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:175
  24: tokio::runtime::context::runtime::enter_runtime<tokio::runtime::scheduler::current_thread::impl$0::block_on::closure_env$0<enum2$<test_tokio::start_server::async_block_env$0> >,tuple$<> >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\context\runtime.rs:65
  25: tokio::runtime::scheduler::current_thread::CurrentThread::block_on<enum2$<test_tokio::start_server::async_block_env$0> >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\scheduler\current_thread\mod.rs:167
  26: tokio::runtime::runtime::Runtime::block_on<enum2$<test_tokio::start_server::async_block_env$0> >
             at C:\Users\user\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.36.0\src\runtime\runtime.rs:348
  27: test_tokio::start_server
             at .\src\main.rs:19
  28: test_tokio::main::async_block$0::closure$0
             at .\src\main.rs:38
  29: core::hint::black_box
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\hint.rs:286
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

More

I can hardly find a useful example.

The doc here also seems wrong.

Originally posted by @fufesou in #6362

@fufesou fufesou added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Feb 23, 2024
@fufesou
Copy link
Author

fufesou commented Feb 23, 2024

It's not easy to reproduce this panic when I directly run by cargo run.

But when I run through F5 in vscode, I can see this panic every run.

@fufesou fufesou changed the title Panic when using tokio::net::windows::named_pipe to process ipc Tokio 1.36.0, panic SHUTDOWN.unpack(current) == 0 || matches!(tick, Tick :: Clear(_)) when using tokio::net::windows::named_pipe Feb 23, 2024
@Darksonn Darksonn added the M-net Module: tokio/net label Feb 25, 2024
@fufesou
Copy link
Author

fufesou commented Apr 12, 2024

@Darksonn Hi, I'm sorry to bother you. Is there any progress on this issue?

@Darksonn
Copy link
Contributor

I missed due to its similarity to #6066. Sorry about that.

Unfortunately, I do not have a windows machine available. Which line is the panic on? Your backtrace says line 19, but that is the loop { line, so it seems like the line numbers don't match.

@fufesou
Copy link
Author

fufesou commented Apr 12, 2024

Thanks for your quick reply.

The code seems to panic after destroying _conn for the first time and then entering loop{.

@Darksonn Darksonn added the E-help-wanted Call for participation: Help is requested to fix this issue. label Apr 23, 2024
@GlenDC
Copy link

GlenDC commented Apr 23, 2024

You can assign it to me @Darksonn

@Darksonn Darksonn assigned GlenDC and unassigned GlenDC Apr 23, 2024
@dswij
Copy link

dswij commented Apr 26, 2024

It's not easy to reproduce this panic when I directly run by cargo run.

But when I run through F5 in vscode, I can see this panic every run.

@fufesou what's the command for this debug run in vscode?

I can't reproduce it with cargo run.

@fufesou
Copy link
Author

fufesou commented Apr 26, 2024

Yes, it's hard to reproduce with cargo run.

You need to debug F5.

1714116755216

@dswij
Copy link

dswij commented Apr 26, 2024

You need to debug F5.

That hotkey is running a command set up by your debugging configuration. Do you have .vscode/launch.json file in your workspace? If so, can you also post it here?

I'm not that familiar with VSCode, so I'm not sure if extensions usually does it for you. But you should be able to find the exact command ran when you invoke debug for Rust projects in VSC.

@fufesou
Copy link
Author

fufesou commented Apr 26, 2024

This is my .vscode/launch.json.

But it's so weird that I cannot reproduce this issue anymore. I've tried 1.37 and 1.36.

I can reproduce it every time with 1.37 just two weeks ago.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'simple_test'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=simple_test",
                    "--package=simple_test"
                ],
                "filter": {
                    "name": "simple_test",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

@dswij
Copy link

dswij commented Apr 26, 2024

Thanks!

I still can't seem to reproduce the issue for both 1.33 and 1.36 even using lldb. Perhaps there's something else?

@fufesou
Copy link
Author

fufesou commented Apr 26, 2024

Ok. I close this issue because it cannot be produced anymore.

Thank you for your time.

@fufesou fufesou closed this as completed Apr 26, 2024
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. E-help-wanted Call for participation: Help is requested to fix this issue. M-net Module: tokio/net
Projects
None yet
Development

No branches or pull requests

4 participants