From 936ff9f213a76e391cadaa3230cf860fe6c7bf7e Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 24 Jun 2022 18:33:33 +0200 Subject: [PATCH] Tokio needs descriptors for timers and more --- src/main.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index af5831d..5a8e758 100644 --- a/src/main.rs +++ b/src/main.rs @@ -523,7 +523,7 @@ fn set_limits(config: &Config) -> Result<(), Error> { #[cfg(target_family = "unix")] fn set_limits(config: &Config) -> Result<(), Error> { use rlimit::Resource; - let nb_descriptors = 2u32 + let nb_descriptors = 4u32 .saturating_mul( config .tcp_max_active_connections @@ -531,19 +531,15 @@ fn set_limits(config: &Config) -> Result<(), Error> { .saturating_add(config.listen_addrs.len() as u32), ) .saturating_add(16); - if Resource::NOFILE - .set(nb_descriptors as _, nb_descriptors as _) - .is_err() - { - let (_soft, hard) = Resource::NOFILE.get()?; - if nb_descriptors as u64 > hard as u64 { - warn!( - "Unable to set the number of open files to {}. The hard limit is {}", - nb_descriptors, hard - ); - } - Resource::NOFILE.set(hard, hard)?; + let (_soft, hard) = Resource::NOFILE.get()?; + if nb_descriptors as u64 > hard as u64 { + warn!( + "Unable to set the number of open files to {}. The hard limit is {}", + nb_descriptors, hard + ); } + let nb_descriptors = std::cmp::max(nb_descriptors as _, hard); + Resource::NOFILE.set(nb_descriptors, nb_descriptors)?; Ok(()) }