Commit e6836579 authored by chenhuaqing's avatar chenhuaqing

fixed authentication error handling

parent d35c3e4a
...@@ -393,41 +393,32 @@ async fn authenticate_server( ...@@ -393,41 +393,32 @@ 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());
let mut res_buf = BytesMut::with_capacity(1);
while retry_count > 0 { return match time::timeout(auth_timeout, auth_stream.read_buf(&mut res_buf)).await {
let mut res_buf = BytesMut::with_capacity(1); Ok(res) => match res {
match time::timeout(auth_timeout, auth_stream.read_buf(&mut res_buf)).await { Ok(len) => {
Ok(res) => match res { debug!("authenticate with remote server recv {}", len);
Ok(len) => { if len == 1 {
debug!("authenticate with remote server recv {}", len); return Ok(Some(auth_stream));
if len == 1 {
return Ok(Some(auth_stream));
}
if len == 0 {
debug!("auth_stream closed by remote server");
return Err(io::Error::from(io::ErrorKind::ConnectionRefused));
}
} }
Err(err) => { if len == 0 {
retry_count -= 1; debug!("auth_stream closed by remote server");
debug!("auth_stream read packet from remote server error: {}", err); return Err(io::Error::from(io::ErrorKind::ConnectionRefused));
continue;
} }
}, 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 timeout: {}", err); Err(io::Error::from(io::ErrorKind::BrokenPipe))
continue;
} }
},
Err(err) => {
debug!("auth_stream read packet from remote server timeout: {}", err);
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