-
According to the document in the
Can you explain it in detail? Why it will cause deadlocks? As far as I know, when we send the // Single thread executor
#[tokio::main]
async fn main() {
let (tx, mut rx) = tokio::sync::mpsc::channel(1);
tokio::spawn(async move {
for i in 0..10 {
tx.send(i).await.unwrap();
println!("Send {i}")
}
});
// Sleep for a while, rx is not being readed now, which will cause the tx.send to sleep
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
while let Some(value) = rx.recv().await {
println!("{value}")
}
} Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Not 100% sure about it. For example, if we want to send A, B, C to the receiver by a bounded channel with capacity = 2.
cc @andygrove . |
Beta Was this translation helpful? Give feedback.
-
Sure, I can explain. Let's say we have 2 input partitions and 2 output partitions, and we use small bounded channels (max 2 record batches). Also, let's assume we have a single thread calling execute for partition 0, reads the results, then calls execute for partition 1. It will not read any results for partition 1 until it has read all results for partition 0, but there are tasks running for the input partitions, trying to write to both output partitions 0 and 1 and 1 will get blocked because it is not being read yet, resulting in a deadlock. Does that make sense? |
Beta Was this translation helpful? Give feedback.
Sure, I can explain. Let's say we have 2 input partitions and 2 output partitions, and we use small bounded channels (max 2 record batches).
Also, let's assume we have a single thread calling execute for partition 0, reads the results, then calls execute for partition 1. It will not read any results for partition 1 until it has read all results for partition 0, but there are tasks running for the input partitions, trying to write to both output partitions 0 and 1 and 1 will get blocked because it is not being read yet, resulting in a deadlock. Does that make sense?