util: Raise open file soft limit at startup on Unix (#64034)

# 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>
d12e456be7Anton Wiehe committed on 9/11/2026, 3:39:49 PM· committed by GitHubparent7ff8e1c
3 files changedLine totals unavailable