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

Unbounded memory use of futures::channel::mpsc with SinkExt::feed #2838

Open
xmakro opened this issue Mar 7, 2024 · 0 comments
Open

Unbounded memory use of futures::channel::mpsc with SinkExt::feed #2838

xmakro opened this issue Mar 7, 2024 · 0 comments
Labels
A-channel Area: futures::channel bug

Comments

@xmakro
Copy link

xmakro commented Mar 7, 2024

The following minimal example has unbounded memory usage:

use futures::SinkExt;

#[tokio::main]
async fn main() {
    let (tx, rx) = futures::channel::mpsc::channel(16);
    for i in 0.. {
        tx.clone().feed(vec![0; 100000]).await.unwrap();
        println!("{i}");
    }
}

The loop keeps running, even when the bounded channel is full, and the program eventually runs out of memory. I would have expected that there is back-pressure when the channel is full and that we only print until we reach 16, but this is not the case. When using SinkExt::send instead of SinkExt::feed, then things work as expected and the send call blocks when the channel is full.

What surprised me even more with feed is that the item is also not dropped when the cloned sender is dropped.

@taiki-e taiki-e added bug A-channel Area: futures::channel labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-channel Area: futures::channel bug
Projects
None yet
Development

No branches or pull requests

2 participants