Closed
Description
Vorner wrote a really insightful post on trying out async/await
with async-std
, and talked about several things that didn't go well. This is a tracking issue to address all the feedback provided.
Also @vorner if you're reading along; thanks so much for the writeup! -- Posts like these are incredibly helpful, and allow us to learn where we need to improve.
Items
- Low rates of connection on localhost (started on in Implement simple work stealing #205)
- Investigate why
TcpListener
sometimes stays open indefinitely - Investigate why connections are timing out
- Document how to enable the
unstable
feature (needed forfuture::timeout
. (solved by Clean up the fs module and a few other places #190 Document feature flags in readme #202) -
futures_rs::select
requiresUnpin
(solved by add future::{join,try_join,select,try_select} macros #187) - Pinning can be tricky (groundwork in expose std::pin #203)
Quotes
But when running it, with both server and client on localhost, sometimes the experiment never finished, even with low rates of new connection creation. This seemed odd.
Still, even with rates like 100 new connections per second, some of the connections were timing out.
Code Example
// expected
async fn connect(server: SocketAddr, content: Arc<[u8]>, mut results: Sender<Duration>) {
let res = timeout(connect_inner(server, content), TIMEOUT).await.unwrap();
res.send().await.unwrap();
}
// current
async fn connect(server: SocketAddr, content: Arc<[u8]>, mut results: Sender<Duration>) {
let connect = connect_inner(server, content);
pin_mut!(connect);
let timeout = task::sleep(TIMEOUT);
pin_mut!(timeout);
match future::select(connect, timeout).await {
Either::Left((Ok(duration), _)) => results
.send(duration)
.await
.expect("Channel prematurely closed"),
Either::Left((Err(e), _)) => error!("Connection failed: {}", e),
Either::Right(_) => {
warn!("Connection timed out");
results
.send(TIMEOUT)
.await
.expect("Channel prematurely closed");
}
}
}