Improve stability by exiting immediately on common errors (#2)

* Kill connections immediately on missing or close

* Add timeout to initial protocol messages

* Add low-level tracing for JSON messages

* Add timeout to initial TCP connections
This commit is contained in:
Eric Zhang
2022-04-08 15:55:54 -04:00
committed by GitHub
parent c1efefeddf
commit 2d0dcf9889
4 changed files with 51 additions and 29 deletions

View File

@@ -13,7 +13,9 @@ use tracing::{info, info_span, warn, Instrument};
use uuid::Uuid;
use crate::auth::Authenticator;
use crate::shared::{proxy, recv_json, send_json, ClientMessage, ServerMessage, CONTROL_PORT};
use crate::shared::{
proxy, recv_json_timeout, send_json, ClientMessage, ServerMessage, CONTROL_PORT,
};
/// State structure for the server.
pub struct Server {
@@ -71,10 +73,7 @@ impl Server {
}
}
let mut buf = Vec::new();
let msg = recv_json(&mut stream, &mut buf).await?;
match msg {
match recv_json_timeout(&mut stream).await? {
Some(ClientMessage::Authenticate(_)) => {
warn!("unexpected authenticate");
Ok(())