From 05043954afd8b0e0a980494aa030dd7be5f1b0a5 Mon Sep 17 00:00:00 2001 From: Ongy Date: Fri, 8 Nov 2024 19:51:56 +0100 Subject: [PATCH] Add hard fileno (#366) * increase the fileno limit This allows wstunnel to use fds>1024. Otherwise heavy use can easily run out of file descriptors on connection attempts. While there will still be a limit, it is significantly higher (~500 times on my system) which provides enough headroom for connections to be torn down and fds to be closed. --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 ++ src/main.rs | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 7339e0e..914cbf6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -765,6 +765,16 @@ dependencies = [ "utf-8", ] +[[package]] +name = "fdlimit" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182f7dbc2ef73d9ef67351c5fbbea084729c48362d3ce9dd44c28e32e277fe5" +dependencies = [ + "libc", + "thiserror", +] + [[package]] name = "filetime" version = "0.2.25" @@ -3128,6 +3138,7 @@ dependencies = [ "crossterm", "fast-socks5", "fastwebsockets", + "fdlimit", "futures-util", "hickory-resolver", "http-body-util", diff --git a/Cargo.toml b/Cargo.toml index 46a6cf9..4f0b012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,8 @@ ppp = { version = "2.2.0", features = [] } async-channel = { version = "2.3.1", features = [] } arc-swap = { version = "1.7.1", features = [] } +fdlimit = "0.3.0" + # For config file parsing regex = { version = "1.11.0", default-features = false, features = ["std", "perf"] } serde_regex = "1.1.0" diff --git a/src/main.rs b/src/main.rs index 3f3ecc6..1012ee0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use base64::Engine; use clap::Parser; use hyper::header::HOST; use hyper::http::{HeaderName, HeaderValue}; -use log::debug; +use log::{debug, warn}; use parking_lot::{Mutex, RwLock}; use std::collections::BTreeMap; use std::fmt::Debug; @@ -727,6 +727,9 @@ async fn main() -> anyhow::Result<()> { } else { logger.init(); }; + if let Err(err) = fdlimit::raise_fd_limit() { + warn!("Failed to set soft filelimit to hard file limit: {}", err) + } match args.commands { Commands::Client(args) => {