Files
codex/codex-rs/app-server/src/managed_daemon.rs
T
Eric Traut 8519cde1ba Raise the managed app-server file descriptor limit on Unix (#51470)
## What changed

For managed app-server daemons using Unix sockets, raise the soft
`RLIMIT_NOFILE` limit to 4096 at startup, capped by the inherited hard limit.
Preserve existing higher soft limits and log a warning if the adjustment fails.

GitOrigin-RevId: 2ef27370e55cd86a7a62cbc3d47041933b89ac21
2026-10-06 19:51:15 +00:00

27 lines
855 B
Rust

//! Unix process setup specific to a managed app-server daemon.
use std::io;
const NOFILE_LIMIT: libc::rlim_t = 4096;
pub(crate) fn raise_nofile_limit() -> io::Result<()> {
let mut limit = libc::rlimit {
rlim_cur: 0,
rlim_max: 0,
};
// SAFETY: getrlimit initializes the stack-owned resource-limit structure.
if unsafe { libc::getrlimit(libc::RLIMIT_NOFILE, &raw mut limit) } == -1 {
return Err(io::Error::last_os_error());
}
let target = limit.rlim_cur.max(limit.rlim_max.min(NOFILE_LIMIT));
if target == limit.rlim_cur {
return Ok(());
}
limit.rlim_cur = target;
// SAFETY: the requested soft limit does not exceed the inherited hard limit.
if unsafe { libc::setrlimit(libc::RLIMIT_NOFILE, &limit) } == -1 {
return Err(io::Error::last_os_error());
}
Ok(())
}