Remote-related bug in tokio-core >= 0.1.13
srijs opened this issue · 3 comments
Hi!
It appears that the new versions of tokio-core
based on tokio
(tokio_core
>= 0.1.13) have broken Rusoto (rusoto/rusoto#1000).
I was able to reduce it to a simple example program that works correctly with tokio_core
0.1.12 (tokio_io
0.1.5), but breaks with tokio_core
0.1.13 or 0.1.14.
Here is the program:
extern crate tokio_core;
use std::thread;
use std::sync::{Arc, Barrier, Mutex};
use tokio_core::reactor::{Core, Remote};
fn spawn() -> Remote {
let slot = Arc::new(Mutex::new(None));
let slot_clone = slot.clone();
thread::spawn(move || {
let mut core = Core::new().unwrap();
let mut guard = slot_clone.lock().unwrap();
*guard = Some(core.remote());
drop(guard);
println!("turning core...");
loop {
core.turn(None);
}
});
loop {
let mut guard = slot.lock().unwrap();
if let Some(remote) = guard.take() {
return remote;
}
}
}
fn main() {
let remote = spawn();
let barrier = Arc::new(Barrier::new(2));
let barrier_clone = barrier.clone();
remote.spawn(move |_| {
println!("waiting in remote");
barrier_clone.wait();
println!("waking in remote");
Ok(())
});
println!("waiting in main");
barrier.wait();
println!("waking in main");
}
The expected behaviour of the program is to print the following and then exit:
turning core...
waiting in main
waiting in remote
waking in remote
waking in main
However, using tokio_core
0.1.13 or 0.1.14, the output is the following, and it never exits:
turning core...
waiting in main
Superficially it looks like the closure passed to remote.spawn
is never executed.
Upon further digging, if I replace
loop {
core.turn(None);
}
with
core.run(futures::future::empty::<(), ()>()).unwrap();
the program works as expected.
Hope that helps!
Thanks for the report. The simple repro case was very helpful.
I pushed #312 with a fix. Could you check against Rusoto to see if it fixes it?
Tested the fix, the issue I reported against Rusoto no longer occurs with the fix applied.