Skip to content

Commit

Permalink
fud v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mariari committed Nov 2, 2023
1 parent 4a526c9 commit e26121d
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::{TryFrom, TryInto};
use std::sync::Arc;

use backoff::ExponentialBackoff;
use backoff::{Error, ExponentialBackoff};

Check warning on line 4 in src/server.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `Error`
use futures::future::{FutureExt, TryFutureExt};
use futures::sink::SinkExt;
use futures::stream::{FuturesOrdered, StreamExt};
Expand Down Expand Up @@ -168,13 +168,15 @@ where

let server = self.clone();
let listener_clone = listener.clone();

tokio::spawn(async move {
let s = server.clone();

backoff::future::retry::<_, BoxError, _, _, _>(
ExponentialBackoff::default(),
|| async {
match listener_clone.accept().await {
Ok((socket, _addr)) => {
let s = server.clone();
let conn = Connection {
consensus: s.consensus.clone(),
mempool: s.mempool.clone(),
Expand All @@ -183,19 +185,12 @@ where
};

if let Err(e) = conn.run(socket).await {
match e.downcast::<tower::load_shed::error::Overloaded>() {
Err(e) => {
tracing::error!({ %e }, "error in a connection handler");
return Err(backoff::Error::Permanent(e));
}
Ok(e) => {
tracing::warn!("Service overloaded - backing off");
return Err(backoff::Error::Permanent(e));
// return Err(backoff::Error::transient(e));
}
}
drop(s);
Err(backoff::Error::Permanent(e))
} else {
drop(s);
Ok(())
}
Ok(())
}
Err(e) => {
tracing::error!({ %e }, "error accepting new tcp connection");
Expand Down

0 comments on commit e26121d

Please sign in to comment.