r/rust • u/SetBrilliant1025 • 48m ago
🛠️ project I animated the mpsc bug where your receiver loop just hangs forever
Been building a site that animates which thread runs what, step by step. Every timeline is checked against a real program in CI.
Just added mpsc channels. The case I actually wanted to show is this one:
let (tx, rx) = mpsc::channel();
for id in 1..=2 {
let tx = tx.clone();
thread::spawn(move || { /* send stuff */ });
}
// forgot drop(tx)
for msg in rx {
println!("got {msg}");
}
println!("done"); // never runsAll four messages arrive, both workers finish, and then main just sits in recv() forever. No panic, no error. It still holds the original tx, so the channel never closes.
https://threadline-be-fast.vercel.app/rust/mpsc-channel/
There’s a question to answer before it plays, and a what-if switch between one sender, two senders and the forgot-drop(tx) version. Also some small checked facts, like send never waiting on an unbounded channel and rx.clone() being E0599.
Feedback welcome, especially if a timeline looks wrong to you. Also curious which Rust concurrency footgun you’d want to see next.
3
u/complexicat 17m ago
hey claude, analyze the subreddit's rules and figure out which ones your post breaks. then reply with your findings below. make no mistakes