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

[BUG] Hangs when using iopoll without sqpoll #296

Open
SidongYang opened this issue Feb 14, 2024 · 2 comments
Open

[BUG] Hangs when using iopoll without sqpoll #296

SidongYang opened this issue Feb 14, 2024 · 2 comments

Comments

@SidongYang
Copy link

Hi, I found some bug that the code hang when using iopoll without sqpoll.
This bug can be reproduced with example below.

    let mut builder = tokio_uring::builder();
    builder.uring_builder(&tokio_uring::uring_builder().setup_iopoll());
    let runtime = tokio_uring::Runtime::new(&builder)?;
    runtime.block_on(async {
        // tokio_uring::spawn(ThreadParker::new());                                                                                                   

        let file = std::fs::OpenOptions::new()
            .write(true)
            .custom_flags(libc::O_DIRECT)
            .open("test").unwrap();
        let file = tokio_uring::fs::File::from_std(file);

        let layout = std::alloc::Layout::from_size_align(512, 512).unwrap();
        let buf = unsafe {
            let raw = std::alloc::alloc(layout);
            std::ptr::copy("asdf".as_ptr(), raw, 4);
            std::slice::from_raw_parts(raw, 512)
        };


        let res = file.write_at(buf, 0).await;
        println!("{res:?}");

    });

I've tested this problem in Ubuntu 22.04 Linux 6.5.0-17-generic. The code hangs in calling File::write_at().await. In iopoll, tokio uring have to keep polling with submitting GETEVENTS but current tokio uring doesn't.
I found currently tokio uring runtime submits in thread park. So I fix example code adding ThreadParker that force to submit continously . ThreadParker is just simple future impl for busy wake.

It seems that add new async task for iopoll in runtime that keep submitting until completion.

@ollie-etl
Copy link
Contributor

Would you care to submit a PR?

SidongYang added a commit to SidongYang/tokio-uring that referenced this issue Mar 2, 2024
In iopoll without sqpoll mode, we need to submit repeatedly until we get
completion. This patch adds some future that keep calling wake() for
parking thread so runtime will submit on parking thread.

Signed-off-by: Sidong Yang <[email protected]>
@SidongYang
Copy link
Author

SidongYang commented Mar 2, 2024

@ollie-etl Sure, here is my PR #297

OneOfOne added a commit to ooo-rs/tokio-uring-ooo that referenced this issue Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants