# Objective Fixes #46470 Relates to #53901, #62486, #20806 Processes launched via GUI (such as `launchd`, Finder, Spotlight, or Dock on macOS) inherit a default soft `RLIMIT_NOFILE` of only 256 open files (lazily raised to 2,560 by Apple frameworks on first use of certain APIs). In active workspaces—especially those running multiple language servers, MCP context servers, active filesystem watchers (`FSEventStream`), and agent tool calls—baseline file descriptor consumption sits near 200–250. During bursts of file activity or shell tool spawning, Zed quickly exhausts this soft limit and fails with `EMFILE (os error 24: Too many open files)`. Similar desktop runtimes and editors (Chromium, VS Code, Node.js, Go, JVM) raise their soft descriptor limit at startup for this exact reason. ## Solution - Added `util::increase_open_file_limit()` called early in `main()` right after tracing initialization. - On macOS, query `getrlimit(RLIMIT_NOFILE)` and raise `rlim_cur` to `limit.rlim_max.min(OPEN_MAX)`, where `OPEN_MAX = 10,240` (from `<sys/syslimits.h>`). Note that macOS `setrlimit(2)` returns `EINVAL` if `rlim_cur > 10240` even when `rlim_max` is `RLIM_INFINITY`. - On other Unix platforms (Linux), raise `rlim_cur` to `limit.rlim_max.min(65536)`. - If the current limit is already at or above the target, it remains untouched. - Added a unit test in `crates/util/src/util.rs` verifying limit querying and retention. ## Testing - Added `test_increase_open_file_limit` in `crates/util/src/util.rs`. - Ran `cargo test -p util` (134 passed, 0 failed). - Ran `cargo check -p zed` (passed cleanly). ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Raised the default open file descriptor soft limit at startup on Unix/macOS to prevent `EMFILE` (`Too many open files`) errors in large workspaces. --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
72 lines
1.7 KiB
TOML
72 lines
1.7 KiB
TOML
[package]
|
|
name = "util"
|
|
version = "0.1.0"
|
|
edition.workspace = true
|
|
publish = false
|
|
license = "Apache-2.0"
|
|
description = "A collection of utility structs and functions used by Zed and GPUI"
|
|
|
|
|
|
[lints]
|
|
workspace = true
|
|
|
|
[lib]
|
|
path = "src/util.rs"
|
|
doctest = true
|
|
|
|
[features]
|
|
test-support = ["rand", "util_macros", "path/test-support"]
|
|
# Embed `fs_embed!` assets at compile time even in debug builds.
|
|
debug-embed = ["rust-embed/debug-embed"]
|
|
|
|
[dependencies]
|
|
anyhow.workspace = true
|
|
async_zip.workspace = true
|
|
collections.workspace = true
|
|
dunce.workspace = true
|
|
futures-lite.workspace = true
|
|
futures.workspace = true
|
|
globset.workspace = true
|
|
itertools.workspace = true
|
|
log.workspace = true
|
|
rand = { workspace = true, optional = true }
|
|
regex.workspace = true
|
|
rust-embed.workspace = true
|
|
schemars.workspace = true
|
|
serde.workspace = true
|
|
serde_json.workspace = true
|
|
serde_json_lenient.workspace = true
|
|
shlex.workspace = true
|
|
take-until.workspace = true
|
|
tempfile.workspace = true
|
|
unicase.workspace = true
|
|
url.workspace = true
|
|
percent-encoding.workspace = true
|
|
util_macros = { workspace = true, optional = true }
|
|
gpui_util.workspace = true
|
|
path = { workspace = true, features = ["serde"] }
|
|
|
|
[target.'cfg(not(target_family = "wasm"))'.dependencies]
|
|
smol.workspace = true
|
|
which.workspace = true
|
|
async-fs.workspace = true
|
|
walkdir.workspace = true
|
|
dirs.workspace = true
|
|
|
|
[target.'cfg(unix)'.dependencies]
|
|
command-fds = "0.3.1"
|
|
libc.workspace = true
|
|
nix = { workspace = true, features = ["resource", "user"] }
|
|
|
|
[target.'cfg(target_os = "macos")'.dependencies]
|
|
mach2.workspace = true
|
|
|
|
[target.'cfg(windows)'.dependencies]
|
|
tendril = "0.5"
|
|
windows.workspace = true
|
|
|
|
[dev-dependencies]
|
|
rand.workspace = true
|
|
util_macros.workspace = true
|
|
path = { workspace = true, features = ["test-support"] }
|