It's not a question about timeouts: When a client has connected to the server it requests to subscribe to a stream of messages. While the server is waiting for a message to arrive [from the internal mpsc channel] to forward to the client, it needs to detect if the client has disconnected.
I'll add some comments to the original code to better illustrate the problem
async fn handle_client_sub_conn(chrx: Receiver<Msg>, frmio: Framed<...>) {
loop {
// This blocks. If the client disconnects while we're waiting for
// for a message to arrive over the channel, then we won't notice
// it here.
let element = chrx.recv().await.unwrap();
let buf = serialize(element);
// It's not until we reach this point where we notice that the
// client has disconnected
frmio.send(buf).await.unwrap();
}
}
The question is simply: How can one detect that the client connection has been lost while waiting for a message to arrive over the mpsc channel. Does one need to attempt a fake read, or is there some other mechanism?