You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The following minimal example has unbounded memory usage:
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 usingSinkExt::send
instead ofSinkExt::feed
, then things work as expected and thesend
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.The text was updated successfully, but these errors were encountered: