Handle timeouts like excessive errors

This commit is contained in:
Mike Dilger 2024-02-20 21:29:40 +13:00
parent 1a90d2f9d5
commit c42452a41a
2 changed files with 20 additions and 3 deletions

View File

@ -103,6 +103,9 @@ pub enum ChorusError {
// Rustls
Rustls(tokio_rustls::rustls::Error),
// Timed Out
TimedOut,
// Tungstenite
Tungstenite(hyper_tungstenite::tungstenite::error::Error),
@ -167,6 +170,7 @@ impl std::fmt::Display for ChorusError {
ChorusError::NoPrivateKey => write!(f, "Private Key Not Found"),
ChorusError::Restricted => write!(f, "Restricted"),
ChorusError::Rustls(e) => write!(f, "{e}"),
ChorusError::TimedOut => write!(f, "Timed out"),
ChorusError::Tungstenite(e) => write!(f, "{e}"),
ChorusError::Scraper => write!(f, "Filter is underspecified. Scrapers are not allowed"),
ChorusError::TooManyErrors => write!(f, "Too many errors"),

View File

@ -299,12 +299,25 @@ async fn handle_http_request(
// Ban for longer if they've had error-based bans already
ban_seconds = 60 + 60 * number_of_error_bans as u64;
msg = "Banned (temporary)";
msg = "Errored Out, temporarily banned (long and growing)";
}
ChorusError::TimedOut => {
is_an_error_ban = true;
let number_of_error_bans = match GLOBALS.ip_data.get(&peer.ip()) {
Some(ipdata) => ipdata.number_of_error_bans,
None => 0,
};
// Ban for longer if they've had error-based bans already
ban_seconds = 60 + 60 * number_of_error_bans as u64;
msg = "Timed Out, temporarily banned (long and growing)";
}
_ => {
log::error!("{}: {}", peer, e);
ban_seconds = 15;
msg = "Banned (short, temporary)";
msg = "Errored, temporarily banned (short, fixed)";
}
}
}
@ -373,7 +386,7 @@ impl WebSocketService {
// And they are idle for 5 seconds with no subscriptions
if last_message_at + Duration::from_secs(5) < instant {
self.websocket.send(Message::Close(None)).await?;
break;
return Err(ChorusError::TimedOut.into());
}
}
}