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

DuplexStream does not participate in coop #4470

Closed
seanmonstar opened this issue Feb 4, 2022 · 1 comment · Fixed by #4478
Closed

DuplexStream does not participate in coop #4470

seanmonstar opened this issue Feb 4, 2022 · 1 comment · Fixed by #4478
Assignees
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. E-easy Call for participation: Experience needed to fix: Easy / not much M-coop Module: tokio/coop M-io Module: tokio/io

Comments

@seanmonstar
Copy link
Member

The tokio::io::duplex() stream types do no participate in coop, so they can starve a task. This minimal example currently hangs:

use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::test]
async fn duplex_coop() {
    let (mut tx, mut rx) = tokio::io::duplex(1024 * 8);
    
    tokio::select! {
        biased;

        _ = async {
            loop {
                let buf = [3u8; 4096];
                let _ = tx.write_all(&buf).await;
                let mut buf = [0u8; 4096];
                let _ = rx.read(&mut buf).await;
            }
        } => {},
        _ = tokio::task::yield_now() => {}
    }
}

We should add coop checks in poll_read and poll_write, similar to what was done for #4291.

@seanmonstar seanmonstar added C-bug Category: This is a bug. E-easy Call for participation: Experience needed to fix: Easy / not much A-tokio Area: The main tokio crate M-io Module: tokio/io M-coop Module: tokio/coop labels Feb 4, 2022
@GongLG
Copy link
Contributor

GongLG commented Feb 4, 2022

Taking a look..

GongLG added a commit to GongLG/tokio that referenced this issue Feb 7, 2022
Add coop checks on pipe poll_read and poll_write.

Fixes: tokio-rs#4470
Refs: tokio-rs#4291, tokio-rs#4300
GongLG added a commit to GongLG/tokio that referenced this issue Feb 8, 2022
Add coop checks on pipe poll_read and poll_write.

Fixes: tokio-rs#4470
Refs: tokio-rs#4291, tokio-rs#4300
GongLG added a commit to GongLG/tokio that referenced this issue Feb 8, 2022
Add coop checks on pipe poll_read and poll_write.

Fixes: tokio-rs#4470
Refs: tokio-rs#4291, tokio-rs#4300
GongLG added a commit to GongLG/tokio that referenced this issue Feb 8, 2022
Add coop checks on pipe poll_read and poll_write.

Fixes: tokio-rs#4470
Refs: tokio-rs#4291, tokio-rs#4300
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-easy Call for participation: Experience needed to fix: Easy / not much M-coop Module: tokio/coop M-io Module: tokio/io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants