Skip to content

StreamExt::buffered and StreamExt::buffer_unordered hangs (again) for n = 0 #2740

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

Closed
LeoniePhiline opened this issue Apr 26, 2023 · 4 comments
Labels
A-stream Area: futures::stream C-question

Comments

@LeoniePhiline
Copy link

LeoniePhiline commented Apr 26, 2023

There was a "fix" (panic - not preferred) in the past:

This assert! was later removed:

I am not sure if this was intentional.

The following project hangs indefinitely:

Cargo.toml

[package]
name = "buffered"
version = "0.1.0"
edition = "2021"

[dependencies]
futures = "0.3.28"
tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread"] }

src/main.rs

use futures::prelude::*;

#[tokio::main]
async fn main() {
    // Assume not knowing the length of this vec in advance.
    let v: Vec<i32> = vec![];

    // Length might be 0.
    let num_concurrent = v.len();

    // Process all in parallel.
    let w = futures::stream::iter(v.into_iter())
        .map(|e| async move {
            // "Processing" ...
            e
        })
        // Process all entries concurrently
        .buffered(num_concurrent)
        .collect::<Vec<i32>>()
        .await;

    // Never finishes.

    println!("{w:#?}"); // Never prints.
}

With a minimum buffered value of 1, the program finishes.

I believe n = 0 should not panic, as the old assert! solution did, but it should pass through directly without buffering.

(Could be worked around by lower-clamping n to 1 in Buffered::new, but I am certain there is a cleaner way.)

@taiki-e
Copy link
Member

taiki-e commented Apr 28, 2023

Both fixes are included in 0.4, not 0.3 that you are using.

@taiki-e taiki-e closed this as completed Apr 28, 2023
@taiki-e taiki-e added C-question A-stream Area: futures::stream labels Apr 28, 2023
@LeoniePhiline
Copy link
Author

LeoniePhiline commented Apr 28, 2023

@taiki-e There is no 0.4?

Not on GitHub releases, no branch, no tag, not on crates.io, not in the futures-rs blog …

Where is 0.4 and why can’t I find it?

@krakow10
Copy link

I'm having this exact issue, 0.4 does not exist?

@BatmanAoD
Copy link
Member

@LeoniePhiline @krakow10 The master branch is 0.4.

@taiki-e Is there any sort of plan for when 0.4 might be tagged/released, and is there any way to track progress towards that? I see the 1.0 milestone ticket, but the last comment there is over 4 years ago. It seems like it would probably be useful to have 0.4-alpha released, even if the stable release is still some years off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-stream Area: futures::stream C-question
Projects
None yet
Development

No branches or pull requests

4 participants