Introduce a timeout when processing incoming messages

We have an hypothesis that the server gets stuck while processing
an incoming message, either because the buffer fills up or because
a handler never completes. This should mitigate that and, once we
add logging, give us some clue as to what is causing it exactly.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-04-08 16:21:39 +02:00
parent 0b1fda3e13
commit 53a7f9c43e

View File

@ -175,8 +175,10 @@ impl Peer {
let incoming = incoming.context("received invalid RPC message")?; let incoming = incoming.context("received invalid RPC message")?;
receive_timeout.set(create_timer(RECEIVE_TIMEOUT).fuse()); receive_timeout.set(create_timer(RECEIVE_TIMEOUT).fuse());
if let proto::Message::Envelope(incoming) = incoming { if let proto::Message::Envelope(incoming) = incoming {
if incoming_tx.send(incoming).await.is_err() { match incoming_tx.send(incoming).timeout(RECEIVE_TIMEOUT).await {
return Ok(()); Some(Ok(_)) => {},
Some(Err(_)) => return Ok(()),
None => Err(anyhow!("timed out processing incoming message"))?,
} }
} }
break; break;