diff --git a/neard/src/main.rs b/neard/src/main.rs index 7ba36737a05..41c060953f2 100644 --- a/neard/src/main.rs +++ b/neard/src/main.rs @@ -59,11 +59,16 @@ fn main() -> anyhow::Result<()> { // to prevent the inner logic from trying to bump it further: // FD limit is a global variable, so it shouldn't be modified in an // uncoordinated way. - const FD_LIMIT: u64 = 65535; - let (_, hard) = rlimit::Resource::NOFILE.get().context("rlimit::Resource::NOFILE::get()")?; - rlimit::Resource::NOFILE.set(FD_LIMIT, FD_LIMIT).context(format!( - "couldn't set the file descriptor limit to {FD_LIMIT}, hard limit = {hard}" - ))?; + const REQUIRED_NOFILE: u64 = 65535; + let (soft, hard) = rlimit::Resource::NOFILE.get().context("rlimit::Resource::NOFILE::get()")?; + if soft < REQUIRED_NOFILE || hard < REQUIRED_NOFILE { + let new_soft = soft.max(REQUIRED_NOFILE); + let new_hard = hard.max(REQUIRED_NOFILE); + rlimit::Resource::NOFILE.set(new_soft, new_hard).context(format!( + "couldn't set the file descriptor limit to ({new_soft}, {new_hard}), \ + current limit = ({soft}, {hard})" + ))?; + } NeardCmd::parse_and_run() }