Consider the following code:
extern crate futures;
extern crate tokio;
use futures::future::{err, ok, Future};
use futures::stream::{once, Stream};
use tokio::executor::current_thread;
fn main() {
current_thread::block_on_all(
once::<(), ()>(Ok(()))
.map(|()| {
let fut = ok::<(), ()>(()).map(|()| println!("spawned future completed"));
current_thread::spawn(fut);
})
.fold((), |_, _| if true { ok(()) } else { err(()) }),
);
}
It's a toy example, but it's a boiled-down example of some real-world code that I have that listens for new incoming TLS connections and, for each one, spawns a future that handles the new connection.
The issue that I'm running into is that while the inner map
executes and spawns fut
, the future fut
itself is dropped without executing. Unfortunately I haven't managed to get a working example yet (if you run that code snippet, it will behave properly) because I'm not sure what parts of my code are the root cause, and I can't post the code I'm working on publicly. But has anyone seen an issue like that or have a hunch as to what's going on?
To be more concrete about the symptoms:
- I expect the spawned future
fut
to execute because of the contract ofblock_on_all
, which says that it only returns once there are no outstanding futures - My server continues running, but the TLS clients that connect report that their connections are immediately closed
- In the debug logging from my server process, I can see that the future is getting dropped, as Tokio logs
tokio_reactor: dropping I/O source: 1
at the same time as the client reports the connection has been closed