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 code just spawns 2 tasks on runtime. Task Y send queries to task X, task X responds to them and task Y awaits on the replies. Task Y gets stuck almost 90% of the time, when one spawned task completes exactly 128 awaits.
This relates well to #2160 and the new coop budget introduced. And is only reproducible on 0.2.14 and above.
use tokio::sync::mpsc;use tokio::sync::oneshot;externcrate rand;use futures::future::FutureExt;use rand::Rng;asyncfnlmao_test(){let(gtx,mut grx):(
mpsc::UnboundedSender<oneshot::Sender<bool>>,
mpsc::UnboundedReceiver<oneshot::Sender<bool>>,) = mpsc::unbounded_channel();
tokio::spawn(asyncmove{letmut ctr = 0;loop{println!("WAITING");ifletSome(i) = grx.recv().await{
i.send(false).unwrap();
ctr += 1;println!("SENT {}", ctr);}else{println!("FINISHED");break;}}});letmut rng = rand::thread_rng();let t = rng.gen_range(200,500);
tokio::spawn(asyncmove{letmut futs = vec![];println!("{} times", t);for _ in0..t {let(tx, rx) = oneshot::channel::<bool>();
gtx.send(tx).unwrap();// If you remove shared(), it works
futs.push(Box::pin(asyncmove{ rx.await.unwrap()}).shared());}letmut ctr = 0;for f in futs {println!("start {}", ctr);if f.await{panic!("iwkms");}println!("end {}", ctr);
ctr = ctr + 1;}}).await;}fnmain(){letmut rt = tokio::runtime::Builder::new().basic_scheduler().enable_all().build().unwrap();
rt.block_on(async{lmao_test().await;});}
The text was updated successfully, but these errors were encountered:
This is a bug in Shared. The issue is the REPOLL case of the match, which always goes around the loop leading to an infinite loop of polling it again and again and again.
Darksonn
added
C-bug
Category: This is a bug.
I-hang
Program never terminates, resulting from infinite loops, deadlock, livelock, etc.
labels
Apr 20, 2020
We were running into tokio's cooperative scheduling, see this bug:
tokio-rs/tokio#2418
I'm sure there's some way to make that work, but in the meantime just switching to smol lets us make progress.
This is the demo I showed at the SF Rust meetup 2022-05-24.
Version
0.2.14 and above
Platform
Darwin, Linux
Description
Tokio runtime gets stuck when using FutureExt::shared.
Short repro: https://gist.github.com/rust-play/20bc6b3c2490cfc721012d3ffb279d81
The code just spawns 2 tasks on runtime. Task Y send queries to task X, task X responds to them and task Y awaits on the replies. Task Y gets stuck almost 90% of the time, when one spawned task completes exactly 128 awaits.
This relates well to #2160 and the new coop budget introduced. And is only reproducible on 0.2.14 and above.
The text was updated successfully, but these errors were encountered: