fix listener stop accept after failure

This commit is contained in:
sijie.sun 2024-08-03 12:40:08 +08:00 committed by Sijie.Sun
parent d5bc15cf7a
commit 4a0adaa3f8
3 changed files with 23 additions and 3 deletions

View File

@ -29,6 +29,7 @@ pub enum GlobalCtxEvent {
ListenerAdded(url::Url),
ListenerAddFailed(url::Url, String), // (url, error message)
ListenerAcceptFailed(url::Url, String), // (url, error message)
ConnectionAccepted(String, String), // (local url, remote url)
ConnectionError(String, String, String), // (local url, remote url, error message)

View File

@ -183,7 +183,7 @@ and the vpn client is in network of 10.14.14.0/24"
#[arg(
long,
help = "path to the log file, if not set, will print to stdout",
help = "latency first mode, will try to relay traffic with lowest latency path, default is using shortest path",
default_value = "false"
)]
latency_first: bool,
@ -528,6 +528,13 @@ pub async fn async_main(cli: Cli) {
));
}
GlobalCtxEvent::ListenerAcceptFailed(p, msg) => {
print_event(format!(
"listener accept failed. listener: {}, msg: {}",
p, msg
));
}
GlobalCtxEvent::ListenerAdded(p) => {
if p.scheme() == "ring" {
continue;

View File

@ -143,7 +143,20 @@ impl<H: TunnelHandlerForListener + Send + Sync + 'static + Debug> ListenerManage
let mut l = listener.lock().await;
global_ctx.add_running_listener(l.local_url());
global_ctx.issue_event(GlobalCtxEvent::ListenerAdded(l.local_url()));
while let Ok(ret) = l.accept().await {
loop {
let ret = match l.accept().await {
Ok(ret) => ret,
Err(e) => {
global_ctx.issue_event(GlobalCtxEvent::ListenerAcceptFailed(
l.local_url(),
e.to_string(),
));
tracing::error!(?e, ?l, "listener accept error");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
continue;
}
};
let tunnel_info = ret.info().unwrap();
global_ctx.issue_event(GlobalCtxEvent::ConnectionAccepted(
tunnel_info.local_addr.clone(),
@ -164,7 +177,6 @@ impl<H: TunnelHandlerForListener + Send + Sync + 'static + Debug> ListenerManage
}
});
}
tracing::warn!("listener exit");
}
pub async fn run(&mut self) -> Result<(), Error> {