From 53a7f9c43e5be422475bd9a5f5fa42093a66a13b Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 8 Apr 2022 16:21:39 +0200 Subject: [PATCH] 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 --- crates/rpc/src/peer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/rpc/src/peer.rs b/crates/rpc/src/peer.rs index 5efee616e1..76fd6aac18 100644 --- a/crates/rpc/src/peer.rs +++ b/crates/rpc/src/peer.rs @@ -175,8 +175,10 @@ impl Peer { let incoming = incoming.context("received invalid RPC message")?; receive_timeout.set(create_timer(RECEIVE_TIMEOUT).fuse()); if let proto::Message::Envelope(incoming) = incoming { - if incoming_tx.send(incoming).await.is_err() { - return Ok(()); + match incoming_tx.send(incoming).timeout(RECEIVE_TIMEOUT).await { + Some(Ok(_)) => {}, + Some(Err(_)) => return Ok(()), + None => Err(anyhow!("timed out processing incoming message"))?, } } break;