Commit e6836579 authored by chenhuaqing's avatar chenhuaqing

fixed authentication error handling

parent d35c3e4a
...@@ -393,13 +393,10 @@ async fn authenticate_server( ...@@ -393,13 +393,10 @@ async fn authenticate_server(
.write_buf(&mut svr_context.auth_context().get_token().as_bytes()) .write_buf(&mut svr_context.auth_context().get_token().as_bytes())
.await?; .await?;
let mut retry_count = svr_cfg.retry_limit();
let auth_timeout = Duration::from_secs(svr_cfg.auth_timeout()); let auth_timeout = Duration::from_secs(svr_cfg.auth_timeout());
let beats_interval = Duration::from_secs(svr_cfg.beats_interval());
while retry_count > 0 {
let mut res_buf = BytesMut::with_capacity(1); let mut res_buf = BytesMut::with_capacity(1);
match time::timeout(auth_timeout, auth_stream.read_buf(&mut res_buf)).await { return match time::timeout(auth_timeout, auth_stream.read_buf(&mut res_buf)).await {
Ok(res) => match res { Ok(res) => match res {
Ok(len) => { Ok(len) => {
debug!("authenticate with remote server recv {}", len); debug!("authenticate with remote server recv {}", len);
...@@ -410,24 +407,18 @@ async fn authenticate_server( ...@@ -410,24 +407,18 @@ async fn authenticate_server(
debug!("auth_stream closed by remote server"); debug!("auth_stream closed by remote server");
return Err(io::Error::from(io::ErrorKind::ConnectionRefused)); return Err(io::Error::from(io::ErrorKind::ConnectionRefused));
} }
Err(io::Error::from(io::ErrorKind::ConnectionRefused))
} }
Err(err) => { Err(err) => {
retry_count -= 1;
debug!("auth_stream read packet from remote server error: {}", err); debug!("auth_stream read packet from remote server error: {}", err);
continue; Err(io::Error::from(io::ErrorKind::BrokenPipe))
} }
}, },
Err(err) => { Err(err) => {
retry_count -= 1;
debug!("auth_stream read packet from remote server timeout: {}", err); debug!("auth_stream read packet from remote server timeout: {}", err);
continue; Err(io::Error::from(io::ErrorKind::TimedOut))
}
} }
time::sleep(beats_interval).await;
retry_count = svr_cfg.retry_limit();
} }
return Err(io::Error::from(io::ErrorKind::TimedOut));
} }
return Ok(None); return Ok(None);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment