Skip to content

Commit

Permalink
Treat TryRecvError::Closed in Inbound::poll_ready as a fatal error
Browse files Browse the repository at this point in the history
Also:
- handle errors in service readiness the same as errors in requests

Closes #1655
  • Loading branch information
teor2345 committed May 24, 2021
1 parent e0bdb50 commit 353f8a8
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions zebra-network/src/peer/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,20 +904,25 @@ where
/// of connected peers.
async fn drive_peer_request(&mut self, req: Request) {
trace!(?req);
use futures::TryFutureExt;
use tokio::sync::oneshot::error::TryRecvError;
use tower::{load_shed::error::Overloaded, ServiceExt};

if self.inbound_service.ready_and().await.is_err() {
// Treat all service readiness errors as Overloaded
// TODO: treat `TryRecvError::Closed` in `Inbound::poll_ready` as a fatal error (#1655)
self.fail_with(PeerError::Overloaded);
return;
}

let rsp = match self.inbound_service.call(req.clone()).await {
let rsp = match self
.inbound_service
.ready_and()
.and_then(|service| service.call(req.clone()))
.await
{
Err(e) => {
if e.is::<Overloaded>() {
if e.is::<TryRecvError>() {
panic!(
"unexpected initialization error in inbound service: {:?}",
e
);
} else if e.is::<Overloaded>() {
// TODO: rate-limit closing connections during inbound service overload (#2107)
tracing::info!(%req, "inbound service is overloaded, dropping request");
tracing::debug!(%req, "inbound service is overloaded, dropping request");
metrics::counter!("pool.overloaded", 1);
} else {
// We could send a reject to the remote peer, but that might cause
Expand Down

0 comments on commit 353f8a8

Please sign in to comment.