mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-23 23:39:10 +00:00
--exit-on-fatal-error option
This commit is contained in:
parent
fe32a65291
commit
c991006f4c
2 changed files with 11 additions and 0 deletions
|
@ -103,6 +103,10 @@ pub struct Args {
|
||||||
/// Daemonize for unix family or run as Windows service
|
/// Daemonize for unix family or run as Windows service
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub daemonize: bool,
|
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> {
|
fn validate_tun(p: &str) -> Result<String> {
|
||||||
|
@ -144,6 +148,7 @@ impl Default for Args {
|
||||||
verbosity: ArgVerbosity::Info,
|
verbosity: ArgVerbosity::Info,
|
||||||
virtual_dns_pool: IpCidr::from_str("198.18.0.0/15").unwrap(),
|
virtual_dns_pool: IpCidr::from_str("198.18.0.0/15").unwrap(),
|
||||||
daemonize: false,
|
daemonize: false,
|
||||||
|
exit_on_fatal_error: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,6 +248,9 @@ where
|
||||||
IpStackStream::Tcp(tcp) => {
|
IpStackStream::Tcp(tcp) => {
|
||||||
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
|
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
|
||||||
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
|
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
|
||||||
|
if args.exit_on_fatal_error {
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);
|
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);
|
||||||
|
@ -271,6 +274,9 @@ where
|
||||||
IpStackStream::Udp(udp) => {
|
IpStackStream::Udp(udp) => {
|
||||||
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
|
if TASK_COUNT.load(Relaxed) > MAX_SESSIONS {
|
||||||
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
|
log::warn!("Too many sessions that over {MAX_SESSIONS}, dropping new session");
|
||||||
|
if args.exit_on_fatal_error {
|
||||||
|
break;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);
|
log::trace!("Session count {}", TASK_COUNT.fetch_add(1, Relaxed) + 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue