Skip to content

Allow overriding the open-file limit for uv run - #525

Closed
zaniebot wants to merge 2 commits into
mainfrom
zb/run-ulimit-20923
Closed

zaniebot wants to merge 2 commits into
mainfrom
zb/run-ulimit-20923

Conversation

@zaniebot

@zaniebot zaniebot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

uv run raises the inherited open-file descriptor limit before launching its command, which can make programs such as tcsh spend substantial time closing every possible descriptor (astral-sh#20923).

Add UV_RUN_ULIMIT to set a command-specific soft open-file limit after uv finishes preparing the environment and immediately before the command is spawned. Preserve the hard limit and reject invalid values or values above it.

@astral-automations-bot astral-automations-bot Bot added the area:configuration Settings and such label Aug 3, 2026
Comment thread crates/uv/src/commands/project/run.rs Outdated
Comment on lines +1324 to +1326
let Some(limit) = std::env::var_os(EnvVars::UV_RUN_ULIMIT) else {
return Ok(());
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should thread this through instead.

Comment thread crates/uv/src/commands/project/run.rs Outdated
Comment on lines +1328 to +1337
let limit = limit.to_str().ok_or_else(|| {
anyhow!(
"Invalid value for `{}`: expected a non-negative integer",
EnvVars::UV_RUN_ULIMIT
)
})?;
let soft = limit
.parse::<u32>()
.with_context(|| format!("Invalid value for `{}`: `{limit}`", EnvVars::UV_RUN_ULIMIT))?;
let soft = rlim_t::from(soft);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be parsed in our environment options handling

Comment thread crates/uv/src/commands/project/run.rs Outdated
Comment on lines +1339 to +1349
let (_, hard) =
getrlimit(Resource::RLIMIT_NOFILE).context("Failed to read the open-file limit")?;
if hard != RLIM_INFINITY && soft > hard {
bail!(
"`{}` value `{soft}` exceeds the hard open-file limit `{hard}`",
EnvVars::UV_RUN_ULIMIT
);
}

setrlimit(Resource::RLIMIT_NOFILE, soft, hard)
.with_context(|| format!("Failed to set the open-file limit to `{soft}`"))?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share utility for doing this update?

@zanieb
zanieb marked this pull request as ready for review August 3, 2026 19:14
@astral-automations-bot

Copy link
Copy Markdown

Promoted to #20926.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:configuration Settings and such

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants