From 5dab0ec264c4021b8ad8ea936bded8bd93a18031 Mon Sep 17 00:00:00 2001 From: doroved Date: Thu, 19 Dec 2024 15:20:32 +0300 Subject: [PATCH] Update proxer-cli to version 0.3.6 and enhance connection limit handling - Bump version of `proxer-cli` in `Cargo.toml` and `Cargo.lock` from 0.3.5 to 0.3.6. - Refactor connection limit handling in `src/server/mod.rs` to improve logging and error handling when setting the maximum open connection limit. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/server/mod.rs | 23 +++++++++++++++-------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03efd01..9c08669 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -744,7 +744,7 @@ dependencies = [ [[package]] name = "proxer-cli" -version = "0.3.5" +version = "0.3.6" dependencies = [ "base64", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 21fbc87..30b53c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proxer-cli" -version = "0.3.5" +version = "0.3.6" edition = "2021" authors = ["doroved"] description = "Proxy TCP traffic on macOS with domain filtering." diff --git a/src/server/mod.rs b/src/server/mod.rs index 8961b37..43264b2 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -16,7 +16,7 @@ use hyper_util::rt::TokioIo; use serde::{Deserialize, Serialize}; use system_proxy::{ProxyState, SystemProxy}; use tokio::net::TcpListener; -use utils::terminate_proxer; +use utils::{terminate_proxer, tracing_error}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct AuthCredentials { @@ -48,15 +48,22 @@ pub async fn run() -> Result<(), Box> { // Parse command-line options let options = Opt::parse(); - // Set open connection limit - let default_connection_limit = rlimit::Resource::NOFILE.get_soft()?; - let _ = rlimit::setrlimit(rlimit::Resource::NOFILE, 999999, rlimit::INFINITY); tracing::info!( - "Setting open connection limit to {}, default limit is {}", - rlimit::Resource::NOFILE.get_soft()?, - default_connection_limit + "Default connection limit (soft, hard): {:?}", + rlimit::Resource::NOFILE.get()? ); + // Set max open connection limit + match rlimit::increase_nofile_limit(rlimit::INFINITY) { + Ok(limit) => { + tracing::info!("Setting max open connection limit to {}", limit); + } + Err(e) => { + tracing::error!("\x1B[31mFailed to increase the open connection limit: {e}\x1B[0m"); + std::process::exit(1); + } + } + // Read the config file or use the default one let config_path = options.config.unwrap_or_else(|| { tracing::info!("Using default config file ~/.proxer-cli/config.json5"); @@ -106,7 +113,7 @@ pub async fn run() -> Result<(), Box> { .with_upgrades() .await { - tracing::error!("Server error: {}", err); + tracing_error(&format!("Server error: {}", err)); } }); }