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

SimplexStream does not close other half on drop #6914

Open
CGamesPlay opened this issue Oct 18, 2024 · 4 comments
Open

SimplexStream does not close other half on drop #6914

CGamesPlay opened this issue Oct 18, 2024 · 4 comments
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-io Module: tokio/io

Comments

@CGamesPlay
Copy link

Version
SimplexStream was introduced in v1.40.0.

Platform
Darwin macbook-pro.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Jun 24 00:58:06 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_ARM64_T6000 arm64

Description

SimplexStream (#6589) doesn't close the other half when the ReadHalf or WriteHalf is dropped. This leads to the other half blocking forever waiting for a read/write which will never finish.

Playground link

use tokio::io::AsyncWriteExt;

#[tokio::main]
async fn main() {
    let (rx, mut tx) = tokio::io::simplex(64);
    drop(rx);
    let buf = [0; 1024];
    println!("write starting");
    tx.write_all(&buf).await.unwrap();
    println!("write finished")
}

I expected to see this happen: the write_all future should resolve to an error.

Instead, this happened: the write_all future never resolves.

This is the same in the other direction as well, where the read calls never resolve if the write half is dropped.

@CGamesPlay CGamesPlay added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Oct 18, 2024
@Darksonn Darksonn added the M-io Module: tokio/io label Oct 18, 2024
@Darksonn
Copy link
Contributor

Problem is we're using ReadHalf/WriteHalf for the simplex stream, and it's hard to change those.

@carllerche
Copy link
Member

The straightforward option would be to have ReadHalf/WriteHalf's inner type be an enum of T & Simplex so it would know how to handle the shutdown. Alternatively, Inner could store some sort of fn pointer or some sort of virtual dispatch strategy as a callback that is invoked when the shutdown happens.

@carllerche
Copy link
Member

Another strategy would be to deprecate simplex and introduce a new io:: method that fixes the issue

@Darksonn
Copy link
Contributor

I don't love adding an enum to ReadHalf/WriteHalf since we're stuck with the enum forever if we do that. I guess this is a sort of dupe of #6878. We shouldn't have reused it in the signature for simplex.

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-io Module: tokio/io
Projects
None yet
Development

No branches or pull requests

3 participants