--exit-on-fatal-error option

This commit is contained in:
ssrlive 2024-10-07 13:23:11 +08:00
parent fe32a65291
commit c991006f4c
2 changed files with 11 additions and 0 deletions

View file

@ -103,6 +103,10 @@ pub struct Args {
/// Daemonize for unix family or run as Windows service
#[arg(long)]
pub daemonize: bool,
/// Exit immediately when fatal error occurs, useful for running as a service
#[arg(long)]
pub exit_on_fatal_error: bool,
}
fn validate_tun(p: &str) -> Result<String> {
@ -144,6 +148,7 @@ impl Default for Args {
verbosity: ArgVerbosity::Info,
virtual_dns_pool: IpCidr::from_str("198.18.0.0/15").unwrap(),
daemonize: false,
exit_on_fatal_error: false,
}
}
}

View file

@ -248,6 +248,9 @@ where
IpStackStream::Tcp(tcp) => {
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
if args.exit_on_fatal_error {
break;
}
continue;
}
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);
@ -271,6 +274,9 @@ where
IpStackStream::Udp(udp) => {
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
if args.exit_on_fatal_error {
break;
}
continue;
}
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);